【发布时间】:2011-08-03 09:34:06
【问题描述】:
我在 asp.net mvc 2 中上传文件时遇到问题。
我的控制器函数的参数是FormCollection 类型。因为字段太多,我无法将每个字段分开作为参数。我的表单中有 2 个上传文件字段。如何在我的控制器中获取上传的文件?
我试过这样:
public ActionResult CreateAgent(FormCollection collection, HttpPostedFileBase personImage)
{
...
}
但personImage 是null。 :(
或者这样:
HttpPostedFileBase img = this.HttpContext.Request.Files[collection["personImage"]];
但img 是null。 collection["personImage"] 也是所选文件的名称(没有路径),我无法将其转换为 HttpPostedFileBase。
请注意,所有字段都必须在一页上填写。我不能让客户在单独的页面中上传图片!
【问题讨论】:
标签: .net asp.net-mvc-2 file-upload upload httppostedfile