I have 4 fileupload
in my form. I want when I click a button, I get the file name and set to model, then the file upload to server. But i don't want must use 4 file, I can use 3, 2, or 1 file upload at a time by choice. If I only use 2 file upload, file3 and file4 model still null. what I must do in my controller ?
Any ideas or suggestion?
Model:
public string file1 {get;set;}
public string file2 {get;set;}
public string file3 {get;set;}
public string file4 {get;set;}
View:
@using (Html.BeginForm("action", "controller", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="files" id="file1" />
<input type="file" name="files" id="file2" />
<input type="file" name="files" id="file3" />
<input type="file" name="files" id="file4" />
<input type="submit" />
}
In Your View :
Note: Here your model names are not required. Through action result parameter you going to pass your files.
In your Controller:
There is an article about file uploading in Codeproject. I didn't checked the above code. Let me know if that is not getting worked.