【发布时间】:2015-10-20 00:51:08
【问题描述】:
我正在尝试使用 ASP MVC 5 从表单上传文件。
但我的file.ContentLength 总是 = 0
public ActionResult Test(int? id, HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
{
//blabla
}
}
这里是我的 .cshtml 表单
using (Html.BeginForm("Test", "MyController",FormMethod.Post, new { id = Model.Id, enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<input type="file" id="file" name="file" />
<div class="form-group">
<button type="submit">Ajouter</button>
</div>
}
【问题讨论】:
标签: c# asp.net razor file-upload