问题 使用ASP.Net MVC的输入类型文件时,Request.Files为空


回发到我的控制器时,我的模型填充了正确的值,我的字符串字段有文件名,但Request.Files为空。

我在视图中的输入是:

<input id="SitePlan" name="SitePlan" type="file" value="<%= Html.Encode(Model.SitePlan) %>" />

我的表单标签以:

 <% using (Html.BeginForm(new { enctype = "multipart/form-data" }))

还有什么我需要设置将字段发送回控制器吗?


1484
2017-09-04 21:10


起源

什么是Model.SitePlan?我相信大多数浏览器都不允许您为<input type =“file”/>分配默认值,但我不确定这是否与您遇到的问题有关。 - Jørn Schou-Rode
我有同样的问题,但我的使用语句看起来像答案:@using(Html.BeginForm(“UploadPatientFiles”,“Wizard”,FormMethod.Post,new {id =“uploadForm”,enctype =“multipart / form -data“}))这可能发生的任何其他原因? - Dan Csharpster


答案:


看一下渲染的<form>标签。没有Html.BeginForm声明只接受您正在使用的htmlAttributes。实际上,它使用html属性作为routeValues。尝试这个...

<% using (Html.BeginForm("actionName", "controllerName", FormMethod.Post, 
   new { enctype = "multipart/form-data" })) { %>

15
2017-09-05 08:14