带有HttpPostedFileBase属性的模型在表单提交时为null

时间:2019-07-12 23:10:46

标签: asp.net-mvc model-view-controller file-upload

我有一个具有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
}

0 个答案:

没有答案