I am facing a weird phenomenon which I can reproduce every time.
My model is:
[Display(Name = "Upload File")]
[DataType(DataType.Upload)]
public System.Web.HttpPostedFileBase file { get; set; }
My Razor is (I leave out the css classes):
@Html.LabelFor(m => m.file)
@Html.EditorFor(m => m.file, new { htmlAttributes = new { @type = "file" } })
The above gives:
Where did the three <input type="file">
come from?
However, if in the model I change the type of file
to string
(instead of HttpPostedFileBase
) then one <input type="file">
shows.
How do I have a file upload control using a Html helper in the Razor page?