Can EditorFor() be used to create <input type=“file”>?

前端 未结 4 653
名媛妹妹
名媛妹妹 2020-12-16 11:16

Given this model, is it possible to use the Html.EditorFor() to render a file upload input element to the page? I played around with the Datatype of the property FileName,

4条回答
  •  再見小時候
    2020-12-16 11:21

    Add: htmlAttributes = new { type = "file" }

    <%: Html.EditorFor(model => model.FileName, new { htmlAttributes = new { type = "file" }}) %> <%: Html.ValidationMessageFor(model => model.FileName) %>

    Note: I'm using MVC 5, I have not tested on other versions.

提交回复
热议问题