上传HttpPostedFile为null [英] Uploaded HttpPostedFile is null
本文介绍了上传HttpPostedFile为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在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中,有这样的事情:
In the Controller, there's something like this:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult About(HttpPostedFile postedFile)
{
//but postedFile is null
View();
}
postedFile
为空在关于()。如何上传文件?
postedFile
is null in About(). How do I upload the file?
推荐答案
使用HttpPostedFileBase(不HttpPostedFile),也正是命名参数作为形式。例如。如果你有
Use HttpPostedFileBase (not HttpPostedFile) and also name the parameter exactly as in the form. eg. if you have
<input type="file" id="file1" name="file1" />
你必须有方法头:
you have to have the method head:
public ActionResult About(HttpPostedFileBase file1)
这篇关于上传HttpPostedFile为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文