asp.net-mvc – HttpPostedFileBase总是在ASP.NET MVC中返回null
发布时间:2020-12-15 19:08:14 所属栏目:asp.Net 来源:网络整理
导读:我有一个问题,当我上传文件在ASP.NET MVC。 我的代码如下: 视图: @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml";}h2Index2/h2@using (Html.BeginForm("FileUpload","Board",FormMethod.Post,new { enctype = "multipart/form-da
我有一个问题,当我上传文件在ASP.NET MVC。
我的代码如下: 视图: @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>Index2</h2> @using (Html.BeginForm("FileUpload","Board",FormMethod.Post,new { enctype = "multipart/form-data" })) { <input type="file" /> <input type="submit" /> } 控制器: [HttpPost] public ActionResult FileUpload(HttpPostedFileBase uploadFile) { if (uploadFile != null && uploadFile.ContentLength > 0) { string filePath = Path.Combine(Server.MapPath("/Temp"),Path.GetFileName(uploadFile.FileName)); uploadFile.SaveAs(filePath); } return View(); } 但uploadFile总是返回null。 解决方法@{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>Index2</h2> @using (Html.BeginForm("FileUpload",new { enctype = "multipart/form-data" })) { <input type="file" name="uploadFile"/> <input type="submit" /> } 您必须提供输入类型文件的名称到uploadfile以便在ASP.net mvc中建模绑定工作,并确保输入类型文件的名称和HttpPostedFileBase的参数名称相同。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 使用ASP.NET Web服务的jQuery AutoComplete(jQuery UI 1.8r
- asp.net-mvc – 如何在多个Asp.net MVC应用程序中使用通用布
- .net – 如何向用户发送电子邮件确认链接
- asp.net-mvc – 使用SimpleInjector为AccountController注册
- asp.net – Azure服务结构:IReliableQueue
- asp.net-mvc – 如何在ASP.NET MVC 4中使用域组作为具有流畅
- asp.net – SelectedValue对DropDownList的SelectedItem.Va
- asp.net-mvc – 为什么Chrome在ASP.NET MVC中提供文件时搜索
- 单元测试 – MVCContrib测试路径与区域
- asp.net – 在后面的代码中通过jquery添加列表框项的问题
推荐文章
站长推荐
- asp.net-mvc-3 – MVC3只读文本框但值必须POST
- ASP.NET Web API正文值限制
- 用户锁定.net 4.5.1 ASP.NET MVC 5
- ASP.NET API接口使用HttpClient进行测试和验证
- asp.net – 在Web.Config的Location Path元素中指
- asp.net-mvc – DataAnnotationsModelBinder如何
- 通过asp.net中的C#将参数传递给CRYSTAL REPORT
- asp.net – 和debug =“false”有什么区别?
- asp.net – WCF与WebAPI和本机移动设备
- 与VS集成的若干种代码生成解决方案[博文汇总(共8
热点阅读