【发布时间】:2011-11-10 17:25:48
【问题描述】:
我添加了一个输入文件字段,但它在控制器上始终为空。我错过了什么?
这是我的视图和控制器的代码。
查看:
...
@using (Html.BeginForm())
{
...
<input type=file name="file" id="file" class="post-attachment" />
...
}
控制器:
[HttpPost]
public ViewResult _Details(HttpPostedFileBase file, ViewTopic viewTopic, string SearchField, string submitBtn)
{
// save file to server
if (file != null && file.ContentLength > 0)
{
var fileName = DateTime.Today.ToString("yy.MM.dd") + Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/Attachments"), fileName);
file.SaveAs(path);
}
...
}
【问题讨论】: