【发布时间】:2011-12-22 12:22:16
【问题描述】:
我正在使用 ASP.NET MVC 3,我想使用 ajax 表单上传图像文件
我的索引视图代码是:
<% using (Ajax.BeginForm("Save","Home", new AjaxOptions() { HttpMethod = "POST", InsertionMode = InsertionMode.Replace }, new { enctype = "multipart/form-data" }))
{%>
<input type="file" /><input type ="submit" value="Submit File"/>
<% } %>
控制器代码为:
[HttpPost]
public ActionResult Save()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View("Index");
}
当我上传文件并单击按钮时,提交了 ajax 表单,但我得到的 Request.File.Count 为 0。
【问题讨论】:
-
我不认为你可以上传这样的文件。我认为大多数异步文件上传器使用隐藏的
iframe技术。但是ianae。
标签: javascript ajax asp.net-mvc-3