【问题标题】:Request.Files is empty when using input type file with ASP.Net MVC将输入类型文件与 ASP.Net MVC 一起使用时,Request.Files 为空
【发布时间】:2010-11-25 18:38:58
【问题描述】:

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

我在视图中的输入是:

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

我的表单标签以:

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

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

【问题讨论】:

  • Model.SitePlan 中有什么?我相信大多数浏览器都不允许您为 分配默认值,但我不确定这是否与您面临的问题有关。
  • 我遇到了同样的问题,但我的 using 语句看起来像答案:@using (Html.BeginForm("UploadPatientFiles", "Wizard", FormMethod.Post, new { id = "uploadForm ", enctype = "multipart/form-data" })) 还有其他原因吗?

标签: asp.net-mvc file-upload


【解决方案1】:

查看呈现的

标记。没有 Html.BeginForm 声明只接受您正在使用的 htmlAttributes。实际上,它使用 html 属性作为 routeValues。试试这个...
<% using (Html.BeginForm("actionName", "controllerName", FormMethod.Post, 
   new { enctype = "multipart/form-data" })) { %>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-04
    相关资源
    最近更新 更多