我试图包含文件上传,它始终保持为NULL。这是我的模型:
[Display(Name = "Upload Document")]
[DataType(DataType.Upload), FileSize(102400)]
public HttpPostedFileBase PathwaysToImpactUploadDocument { get; set; }
我的观点: ProjectForm.cshtml
@Html.EditorFor(m => m.PathwaysToImpactUploadDocument)
Upload.cshtml
@model HttpPostedFileBase
@{
Layout = "~/Views/Shared/EditorTemplates/_Layout.cshtml";
}
@Html.TextBox("", null, new {@class = "form-control", type = "file"})
@Html.ValidationMessage("")
控制器:
[HttpPost]
public ActionResult New(ProjectCreateViewModel model){
}
但 model.PathwaysToImpactUploadDocument 始终为NULL。我错过了什么?
答案 0 :(得分:2)
这里有几件事似乎令人怀疑:
我会确保你的观点看起来像:
@model ProjectCreateViewModel
@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.TextBoxFor(m => m.file, new {@class = "form-control", type = "file"})
@Html.ValidationMessageFor(m => m.file)
<input type="submit">Upload</input>
}