How do you pass parameters in ASP.net MVC over two views, like a wizard?
Or what is the best practice?
I am working on an inhouse bug tracking ASP.net application being moved to MVC, I can’t seem to shake the ASPX out of my head and am going in circles.
In the ASPX application.
Page1 -> Select Project, pass projectId in Querystring
Page2 -> Select IssueType, pass projectId and Issuetype in Querystring
Page3 -> Create New Issue, we can get the projectId and IssueType form querystring
How do we recreate the above flow in MVC?
A common practice for ‘wizard’ type systems is to use a single
<form>element, with information from previous screens in hidden fields.Edit: per the request, here’s an example (I’m not familiar with ASP.net, so you’ll have to translate this into code yourself 🙁 ). Say you have a site that sells cars, and in your ordering form first you ask about the model car, and in subsequent screens you offer options that apply to that vehicle.
When the user selects a model and submits the form, the controller for
order-wizard.htmlcan notice that thestepoption is 1, and knows to check that the user selected a model. Then it gan generate a page like this: (assuming the user selected “pickup”)If the wizard needed to collect more information, There could be additional pages produced in this way with hidden inputs. Otherwise, If this was the last page and all information was gathered, the code for that page could then process the form as normal, as though all inputs had been given by the user on a single page request.
The advantage of this technique is that the server does not need to cache any session information. Another advantage is that it provides a sort of RESTful interface, where a single page request from another tool can generate all of the inputs for the form, skipping over the intermediate wizard pages.
A disadvantage is that since the page is generated dynamically based on user requests, the client will have to start over if they happen to navigate away from the page. Bookmarks just won’t work. It doesn’t save you anything in validation, either, since form inputs of this sort could be faked easily.