0

我有一个带有文件输入的表单,可以很好地处理 HTML 表单。当我提交表单时,我可以在文件输入中获取我的值;但是当使用 AJAX 时,文件输入字段始终为空。

这行得通

@using (Html.BeginForm("ProcessSubmit", "Upload",
                     FormMethod.Post, new { id = "uploadForm", enctype =   "multipart/form-data" })) { 
    @(Html.Telerik().Upload().Name("attachments"))
    <p class="note">
    Maximum combined file size: 10 MB
   </p>
   <div style="margin: 20px 0 0 0;">
       <input type="submit" value="Send" class="t-button" />
       <input type="reset" value="Reset" class="t-button" />
   </div>
}    

and the controller: 
[HttpPost]
    public ActionResult ProcessSubmit(IEnumerable<HttpPostedFileBase> attachments)
    {
        if (attachments != null)
        {
            return Content("is not null");
        }
        return Content("null");
    }

但这不起作用

@using (Ajax.BeginForm("ProcessSubmit", "Upload",
                     new AjaxOptions { UpdateTargetId = "mydiv" })) { 
     <div id="mydiv"></div>
    @(Html.Telerik().Upload().Name("attachments"))
    <p class="note">
    Maximum combined file size: 10 MB
   </p>
   <div style="margin: 20px 0 0 0;">
       <input type="submit" value="Send" class="t-button" />
       <input type="reset" value="Reset" class="t-button" />
   </div>
}  

在前者中,控制器总是返回“不为空”,而在后者中,它总是返回空值。:(

请问这是怎么回事?

4

0 回答 0