Is there a HTMLHelper
for file upload? Specifically, I am looking for a replace of
<input type="file"/>
using ASP.NET MVC HTMLHelper.
Or, If I use
using (Html.BeginForm())
What is the HTML control for the file upload?
Is there a HTMLHelper
for file upload? Specifically, I am looking for a replace of
<input type="file"/>
using ASP.NET MVC HTMLHelper.
Or, If I use
using (Html.BeginForm())
What is the HTML control for the file upload?
This also works:
Model:
View:
Controller action:
List of contentTypes
This is a little hacky I guess, but it results in the correct validation attributes etc being applied
I had this same question a while back and came across one of Scott Hanselman's posts:
Implementing HTTP File Upload with ASP.NET MVC including Tests and Mocks
Hope this helps.
To use
BeginForm
, here's the way to use it:You can also use:
Improved version of Paulius Zaliaduonis' answer:
In order to make the validation work properly I had to change the Model to:
and the view to:
This is required because what @Serj Sagan wrote about FileExtension attribute working only with strings.