我有一个具有HttpPostedFileBase
属性的模型,该模型映射到表单上的文件上传输入。选择文件并提交表单时,映射到文件上载输入的model属性为null。我该如何解决这个问题?
型号:
public class Contact
{
public HttpPostedFileBase AttachmentDocument { get; set; }
}
查看:
using(Html.BeginForm("Create", "ContactForm", FormMethod.Post, new { @entype = "multipart/form-data", @class = "form-horizontal", @id = "contactform" }))
{
<div class="form-group row">
<div class="col-sm-3">Attached Document:</div>
<div class="col-sm-9">
@Html.TextBoxFor(model => model.AttachedDocument, new { @type = "file" })
</div>
</div>
}
操作:
[HttpPost]
public ActionResult Create(Models.Contact model)
{
//AttachmentDocument is null on submit
}