I read some articles that is not possible to save files using Ajax.BeginForm
.
I have a form in MVC5 that uses Ajax.BeginForm
so the user has a nice responsive app without page refresh.
Now, the requirement is to add 4 fields that will hold files (file upload).
Also read that maybe with jquery.form.js
this is possible.
So my questions are about other approach is this make any sense:
- The form keep the
Ajax.BeginForm
- The user enters data into the form.
- When user needs to load a file into the form, then I was thinking on uploading that file to server on the fly and store there temporarily.
- When the form is saved, on server side I can get temp files and then save them.
Does this make any sense? Appreciate any advice from people already facing this situation.
Please check below code for save separate Form Data and File Upload :
View with Ajax.BeginForm
File Upload Button Click Event :
Here is the code for file upload
Hope this will help you !!
You cannot use the MVC Ajax helper with files upload. Instead, you can use the jquery form plugin, on a normal
Html.BeginForm()
.Example:
You use the
onComplete
andbeforeSerialize
callbacks to handle the response.onComplete
is called after the AJAX is done, and if youconsole.log
its arguments, you will see it contains the AJAX response (json / html).Try something like this:
Add this