在 View 上:
<% =Html.BeginForm("About", "Home", FormMethod.Post, new {enctype="multipart/form-data "})%>
<input type="file" name="postedFile" />
<input type="submit" name="upload" value="Upload" />
<% Html.EndForm(); %>
在Controller中,有这样的东西:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult About(HttpPostedFile postedFile)
{
//but postedFile is null
View();
}
postedFile
在 About() 中为空。如何上传文件?
最佳答案
使用 HttpPostedFileBase(不是 HttpPostedFile),并按照表单中的名称准确命名参数。例如。如果你有
<input type="file" id="file1" name="file1" />
你必须有方法头:
public ActionResult About(HttpPostedFileBase file1)
关于c# - 上传的 HttpPostedFile 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/544182/