0

I have a multi-step data entry form in my ASP.NET MVC application.

When the information is posted, the input values are checked and if I determine that some related data is required (e.g. a purchase order references a supplier that does not exist) I redirect to another action so that the user can enter the extra data.

I do not want the values that have already been entered by the user to be lost between pages so I am passing these to the second action method using a viewModel. The data is contained in hidden inputs on the second page so that the user can not see them.

This works fine except I end up with a URL that looks something like this:

myDomain/RFQ/CreatePart?PartNumber=Skateboard&Supplier=Bobs%20skateboards&DateCreated=08%2F28%2F2012%2000%3A00%3A00&DateRequired=08%2F28%2F2012%2000%3A00%3A00&Quantities=1%2C%203%20%26%205%20off

I have tried simply returning a view instead of redirecting which gives me the URL Like this:

myDomain/RFQ/CreatePart

However, this gives me the problem of the user being able to repost the values by refreshing the browser as I am now no longer following the post, redirect, Get pattern.

Is there a way of properly using the Post-Redirect-Get pattern whilst maintaining the cleaner URL?


Update 29th September 2012

I investigated the options listed below and have decided on using SessionState for the time being as this allows me to store intermediate data until the user has finished their transaction whilst allowing me to use the post-redirect-get pattern with a clean URL.

I was actually aware of SessionState prior to asking this question but unfortunately some of the information I had read about it had led me to believe this was not the best solution (most articles cite poor performance but rarely provide any evidence of this or explain why).

Having read this article I now understand SessionState a lot better.

4

1 回答 1

2

Options are as follows (order does not imply better or worse)

  1. Add the values to TempData and they will be available until they are read on the next request by that user and then automatically cleared.
  2. Save the intermediate steps to the database.
  3. Save the intermediate steps In the Cache (if the data is shared amongst users).
  4. Save the intermediate steps to the SessionState (if the data is per-user).
  5. who cares in this case if it's an ugly intermediate URL?
于 2012-09-03T16:12:27.683 回答