jquery-mobile - MVC4 Controller 中的 IEnumerable<HttpPostedFileBase> 集合始终为 null

标签 jquery-mobile file-upload asp.net-mvc-4

我在一个表单中有文本输入字段和多个文件上传。直到运行时我才知道文件或其他字段的数量。

<form action="/WorkOrder/Install" enctype="multipart/form-data" method="post">    
        <div class="display-label">
            Description
        </div>

        <input id="description" name="description" type="text" value="" />

        <div class="display-label">
            Photo - Before Install 
        </div>

        <input name="files" id="file1" type="file" />

        <div class="display-label">
            Photo - After Install 
        </div>

        <input name="files" id="file2" type="file" />

        <input type="submit"/>
</form>

正在填充 FormCollection,但 HttpPostedFileBase 集合始终为 null。 Request.Files 为空。

    [HttpPost]
    public ActionResult Install(FormCollection formCollection, IEnumerable<HttpPostedFileBase> files)
    {
        return View();
    }

我尝试只有一个文件输入并更改 Controller 以接受单个 HttpPostedFileBase,问题是相同的。

最佳答案

jQuery Mobile 正在尝试处理表单提交。我必须在表单上设置 data-ajax="false"才能让 MVC Controller 处理文件上传。

关于jquery-mobile - MVC4 Controller 中的 IEnumerable<HttpPostedFileBase> 集合始终为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13423206/

相关文章:

javascript - 将数据从一个页面传输到另一个 jQuery Mobile

javascript - 移动设备上的 Fancybox 内联弹出窗口不随页面滚动移动

javascript - 使用 jQuery ajax() 时 FormData 为空

javascript - 调用 Array.length 时出现未知错误

asp.net-mvc-4 - Razor MVC,将可跨母版页、partiview 和 View 访问的全局变量放在哪里?

javascript - 如何在 jQuery Mobile 中正确定位元素?

javascript - 应用程序在呈现 Jquery Mobile 之前显示无样式的 Html

symfony - 使用 OneupUploaderBundle 上传实体文件的简单示例

forms - 为什么我不能使用结构语法将文件类型的表单字段传递给 CFFUNCTION?

.net - 使用 x-www-form-urlencoded 而非 application/json 发布时绑定(bind) JSON