ASP.NET MVC3 RAZOR:文件上载给出文件计数为零
发布时间:2020-05-22 11:16:00 所属栏目:asp.Net 来源:互联网
导读:我需要使用带有RAZOR的MVC3将多个文件上传到Web服务器.我有以下代码.在控制器中,我的文件数为零.如何更正它以获取上传的文件的实际数量并获取内容? public class MyFileController : Controller{ public ActionResult MyFileProcessActionTest() { return Vi
|
我需要使用带有RAZOR的MVC3将多个文件上传到Web服务器.我有以下代码.在控制器中,我的文件数为零.如何更正它以获取上传的文件的实际数量并获取内容? public class MyFileController : Controller
{
public ActionResult MyFileProcessActionTest()
{
return View();
}
[HttpPost]
public ActionResult MyFileProcessActionTest(IEnumerable<System.Web.HttpPostedFileBase> files)
{
int fileCount = files.Count<System.Web.HttpPostedFileBase>();
return RedirectToAction("Index");
}
}
视图 @{
ViewBag.Title = "MyFileProcessActionTest";
}
<h2>MyFileProcessActionTest</h2>
@using (Html.BeginForm())
{
<input type="file" name="files" id="file1" />
<input type="file" name="files" id="file2" />
<input type="submit" />
}
读: > Binding HttpPostedFileBase using Ajax.BeginForm 解决方法更改您的表单以匹配以下内容@using(Html.BeginForm("action","controller",FormMethod.Post,new{encType = "multipart/form-data"})){
{
<input type="file" name="files[0]" id="file1" />
<input type="file" name="files[1]" id="file2" />
<input type="file" name="files[2]" id="file3" />
<input type="submit" />
}
索引0,1,2将允许modelbinder绑定到IEnumerable,此外还必须在将文件发布到服务器时指定encType (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- webforms – ASP.Net Core 1.0是否支持WebForm项目
- ASP.NET MVC中的单元测试比Web窗体更好?
- asp.net-mvc – 文件“/ Views/Position/Edit.cshtml”不能
- asp.net-mvc – MVC5 Html.RenderAction与不同的控制器
- 在ASP.NET MVC网站中无法获取详细的错误信息
- asp.net-web-api – Web API 2是否可以通过编程方式加载路由
- asp.net-mvc – 单元测试中的ViewResult.ViewName属性为空
- asp.net-mvc – 实体框架:已经有一个与此命令关联的开放Da
- asp.net-mvc-4 – 如何在Kendo UI Grid中扩展页面加载时的所
- asp.net-mvc – MVC会话过期而不是身份验证
推荐文章
站长推荐
- asp.net-mvc – VS 2015:无法加载文件或程序集’
- asp.net-mvc – ASP.NET MVC – 使用Moq框架对Re
- TeamCity – 在ASP.net网站上发布的问题
- 问题在ASP.NET中使用System.Web.Caching.Cache类
- asp.net-mvc – 如何使用Ninject将服务注入授权过
- asp.net-mvc – 不应加载引用程序集以执行
- asp.net-identity交易问题
- asp.net – IIS 7.5无法打开处理程序映射?
- asp.net-mvc – 尝试将asp.net web发布到Azure时
- asp.net-mvc – Nuget如何指定包位置?
热点阅读
