I have created a dynamic form generator for my company. It allows the users to create different form fields with different names. Processing the form is easy, but the file upload has been a nightmare, because the name of the form field is not known for the controller. In my case, the form field can be like this:
<input type="file" name="certificate" accept=".pdf" />
or
<input type="file" name="course-certificate" accept=".pdf, .docx" />
it can even have one or more file fields in one form
The problem is that when it goes to the post method after submitting the form, I am supposed to have a parameter for the files. It can either be a single file like:
[HttpPost]
public ActionResult Create(HttpPostedFileBase file) // For a single file upload
{
}
or
[HttpPost]
public ActionResult Create(IEnumerable<HttpPostedFileBase> files) // For multiple file uploads
{
}
But I need to send the files with random names that can even have a dash in the middle. What is the solution for this? I don't want to use any kind of jQuery to prepare the form before sending it, I want to be able to send the form as it was reated and receive it in my controler just like that.
Request.Files