HttpPostedFileBase not binding to model

回眸只為那壹抹淺笑 提交于 2019-12-03 05:11:51

Make sure you've set the enctype attribute on your form to multipart/form-data on your form if you want to be able to upload files:

@using (Html.BeginForm("AddFaultType", "Administration", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    ...
}

Completing Darin's answer: Make sure you've set the enctype attribute on your form to multipart/form-data on your form if you want to be able to upload files:

@using (Html.BeginForm("AddFaultType", "Administration", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    ...
}

To ensure your <input> is transmitted to the controller as part of the model use the Html Helpers for Id and name like below:

<input type="file" id="@Html.IdFor(x=>x.HttpPostedFileBase)" name="@Html.NameFor(x=>x.HttpPostedFileBase)" accept=".csv,.txt"/>

Works in MVC5 sorry I cant find any reference to which helpers are available in MVC3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!