我有一个带有文件输入的表单,可以正常使用HTML表单。当我提交表单时,我可以在文件输入中获取我的值;但是当使用AJAX时,文件输入字段始终为null。
这项工作
@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>
}
在前者中,控制器总是返回“is not null”,而在后者中它始终返回null。 :(
请问这是什么?