作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
在 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/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!