Using Asp.Net MVC 4, I have a requirement to upload a file in two steps:
- First page in modal window: pick a file to upload and click submit button. Send the file to the server read first line in the file and return message to client to be displayed on second page.
- Second page (in the same modal window): display message returned from first step and if user decides to save file content to server, the file is sent again to server. Read file content and save it to database.
I'm using Ajax to submit and load page1
and page2
partial views and strongly typed viewModel:
public class MyViewModel
{
public HttpPostedFileBase MyFile { get; set; }
}
I have to use JQuery and Ajax as I have to change modal window content with partial views without reloading the hole web page or changing URL.
In order to send the file a second time to server, I need to send the model (that contains the file: HttpPostedFileBase
) back to client which is done via Ajax get action. And again submit the model to server using second Ajax post.
How can I maintain HttpPostedFileBase
object content to the second submit?