有一个处理文件上传的控制器方法:
AcceptVerbs(HttpVerbs.Post)]
public ActionResult FileUpload(int id, HttpPostedFileBase uploadFile)
{
if (uploadFile != null && uploadFile.ContentLength > 0 && ...)
...
}
当我使用 Html.BeginForm 时,一切正常。将 Html.BeginForm 替换为 Ajax.BeginForm 会导致 uploadFile 的值为空(上述方法的第二个参数):
<div id="ajaxDocumentUpload">
@{ using (Ajax.BeginForm("FileUpload", "ProjectDocument", FormMethod.Post,
new AjaxOptions { OnSuccess = "UploadSuccess" },
new { enctype = "multipart/form-data" }))
{
<div>
<input type=file accept="image/gif, image/jpeg" name="uploadFile">
</div>
<div>
<input type="hidden" name="id" id="id" value="@Model.ProjectId"/>
</div>
<input id=btnUpdateAttachment type=submit value="Upload">
}
}
</div>
知道有什么问题吗?提前感谢您的帮助!