我有以下简化代码:
@using (Html.BeginForm()) {
<div class="editor-field">
@Html.TextBoxFor(m => m.Name)
@Html.ValidationMessageFor(m => m.Name)
</div>
<input type="file" name="file" />
<p>
<input type="submit" value="Submit" />
</p>
}
即使选择了某个文件,它也会显示为null。不确定我做错了什么。
[HttpPost]
public ActionResult Register (Model model, HttpPostedFileBase file)
{
if (ModelState.IsValid)
{
if (file != null && file.ContentLength > 0)
{
string s = file.FileName;
}
...