我有这样的控制器:
public ActionResult SaveBook(Book coll, HttpPostedFileBase EBook)
{
}
并查看如下:
@using (Html.BeginForm("SaveBook", "Book", FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Book</legend>
<table>
<tr>
<td>@Html.LabelFor(model => model.Title)</td>
<td>@Html.EditorFor(model => model.Title)@Html.ValidationMessageFor(model => model.Title)</td>
</tr>
<tr>
<td>@Html.LabelFor(model => model.ISBN)</td>
<td>@Html.EditorFor(model => model.ISBN)@Html.ValidationMessageFor(model => model.ISBN)</td>
</tr>
<tr><td>@Html.LabelFor(model => model.EBook) </td><td>@Html.TextBoxFor(model => model.EBook, new { type = "file", accept = ".pdf" })
@Html.ValidationMessageFor(model => model.EBook)</td></tr>
</table>
<p>
<input type="submit" value="SaveBook" />
</p>
</fieldset>
}
我的模型是这样的:
[Required(ErrorMessage = "Title Required")]
public String Title { get; set; }
[Required(ErrorMessage = "ISBN Required")]
public String ISBN { get; set; }
public HttpPostedFileBase EBook { get; set; }
但我仍然从“EBook”对象或控制器的“coll”对象中的 EBook“null”值中获得价值。有什么建议吗?