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

时间:2009-09-04 21:10:11

标签: asp.net-mvc file-upload

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

我在视图中的输入是:

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

我的表单标签以:

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

我需要设置其他任何东西才能将字段发送回控制器吗?

1 个答案:

答案 0 :(得分:15)

看一下&lt; form&gt;呈现的标记。没有Html.BeginForm声明只接受您正在使用的htmlAttributes。实际上,它使用html属性作为routeValues。试试这个......

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