ASP.NET MVC3 RAZOR:文件上载给出文件计数为零
发布时间:2020-12-15 23:56:16 所属栏目:asp.Net 来源:网络整理
导读:我需要使用带有RAZOR的MVC3将多个文件上传到Web服务器.我有以下代码.在控制器中,我的文件数为零.如何更正它以获取上传的文件的实际数量并获取内容? public class MyFileController : Controller{ public ActionResult MyFileProcessActionTest() { return V
我需要使用带有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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 在Azure上增加AppPool超时的优点/缺点
- 如何在ASP.NET Core应用程序运行Vue并且部署在IIS上详解
- asp.net – 如何在我的自定义MvcRouteHandler中模拟IgnoreR
- asp.net-mvc – 哪个选择:ASP.NET MVC或RESTful WCF?
- asp.net-mvc – ASP.NET MVC – 从查询字符串中获取对象列表
- Exp5 MSF基础应用 20164320 王浩
- asp.net-web-api – ASP.NET Web API中的回调方法
- asp.net-mvc – Html.Actionlink作为Button效果
- asp.net-core – 在以下可用的中间件中定义变量
- 线程机制、CLR线程池以及应用程序域
推荐文章
站长推荐
- ASP.NET MembershipProvider加密/解密
- asp.net – 什么是DefaultWsdlHelpGenerator.asp
- asp.net-mvc – MVC @ Html.CheckboxFor在表单提
- ASP.NET MVC3中基于权限的授权
- 认证 – asp.net mvc 3:Page.User.IsInRole(“x
- asp.net-core – Namespace .AspNetCore.Hosting
- model-view-controller – 具有多个ViewModel的M
- asp.net – 允许搜索机器人在没有会话ID的情况下
- .net – 任何具有Postsharp生产经验的人?
- 用ASP.NET MVC阻止ZmEu攻击
热点阅读