【发布时间】:2012-08-08 17:13:14
【问题描述】:
我在一个非常大的表单中输入了这个文件上传输入:
<input class="input-file" type="file" name="picture">
我正在使用:
public ActionResult Add(FormCollection form)
为了获取我的其余表单值,它也在 FormCollection 中提供了“图片”,但它只有文件名而不是实际图片。我试过用这个:
public ActionResult Add(FormCollection form, HttpPostedFile picture)
还有这个
Request.Files[0]
这是我在其他 SO 问题上找到的解决方案,但都为空。
我认为该文件实际上已被发布,因为它显示在 FormCollection 中。
我怎样才能得到这个文件?试图将其作为 byte[] 保存在数据库中。
谢谢。
【问题讨论】:
-
您的表单有
enctype="multipart/form-data"吗? -
@VladCiobanu 我正在使用
@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl }))开始我的表单...如果尚未完成,我将如何向其中添加多部分?感谢您的帮助。 -
我已将其更改为
@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl, enctype="multipart/form-data"}))并遇到同样的问题。
标签: html asp.net-mvc