我只是試圖創建一個表單,我可以輸入名稱並上傳文件。這裏的視圖模型:將HttpPostedFileBase傳遞給控制器方法
public class EmployeeViewModel
{
[ScaffoldColumn(false)]
public int EmployeeId { get; set; }
public string Name { get; set; }
public HttpPostedFileBase Resume { get; set; }
}
我的觀點:
@using (Html.BeginForm("Create", "Employees", FormMethod.Post))
{
@Html.TextBoxFor(model => model.Name)
@Html.TextBoxFor(model => model.Resume, new { type = "file" })
<p>
<input type="submit" value="Save" />
</p>
@Html.ValidationSummary()
}
而且我控制器的方法:
[HttpPost]
public ActionResult Create(EmployeeViewModel viewModel)
{
// code here...
}
的問題是,當我張貼到控制器的方法,簡歷屬性空值。 Name屬性被傳遞得很好,但不是HttpPostedFileBase。
我在這裏做錯了什麼?
+1約Html.editor的是什麼,而不是Html.TextBoxFor你可以給自己的路 – Nikos 2012-12-21 21:56:05