MVC3 VB.NET Application. I have multiple file upload boxes on a form in my mvc3 application. Request.Files shows 3 files when I put a break point in the below function and look at it.. Problem is other than coding a counter and using a select case I dont see a way to handle saving each file name to the database column it belongs to… Is there away to assign the variable on the fly I guess you could say So that the foreach loop would drop the file in the correct column.. Ie handoutFile1, handoutFile2 , handoutFile3, Etc…. As it stands the below will overwrite the filename in handoutfile1 every time the loop is gone through….I thought about throwing a counter in the loop and just put a select case on it to assign the db column based on the counter number. Seems like a cheap work around though.
For Each File As String In Request.Files
Dim hpf As HttpPostedFileBase = TryCast(Request.Files(File), HttpPostedFileBase)
If hpf.ContentLength = 0 Then
Continue For
End If
Dim savedfileName As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory) + "\CourseHandouts\" + hpf.FileName
hpf.SaveAs(savedfileName)
_filename = hpf.FileName
courses.handoutFile1 = _filename
Next
I dont know VB.Net but i will try to answer in C# code,
In your action you can define in parameter as
and in the view like the following,