I’m using microsoft’s MVC platform to create a web application. In this application, users will fill out a HTML form, click submit, get redirected to a successful message page and receive a printout in pdf form of the form. In addition, I also want to save their entries in the form in a database. I’m using iTextSharp to create and edit the PDF.
I’m looking for advice on managing the workflow in MVC. Specifically, I have a controller method that would direct the workflow for :
- saving the form entries to a database,
- creating and editing the PDF,
- directing the user to a success page,
- returning the PDF for the user to download.
My major question is: how should I delegate the tasks of redirecting to the success page and returning the pdf? As of right now, my controller seems to be able to return only one or the other. Can I redirect to a View that “comes with” a PDF?
What I do in a case like this is create a controller action that returns the PDF associated with a given entry id in the database.
Then the controller action which handles the form POST does the following:
Then the success view can use the id it has been given to either link to the PDF (as a download link) or can embed it in an iframe (yuck!).
Note that this only works because you are saving the values in a database. If don’t use a database, you have to either:
Hope that helps.