views:

40

answers:

1

I am looking for clean approach on the "Edit/Review/Save" scenario in asp.net mvc:

Our customers can "edit" their accounts information which will affect their monthly premium, but before saving the information we need present them with "review" screen where they can review their changes and see a detailed break down of their monthly premium and if they accept it then we do "Save".

Basically it is a three step editing:

step 1 - "Edit" - screen where user edits their information step 2 - "Review" - read only information on the screen for reviewing entered data step 3 - "Save" - the actual save of the data.

What makes it interesting is that there is a many small different "edit" screens, however there is only ONE "review" screen.

it is possible by storing data in session on Edit/Post and retreaving it back on save, but it does not feel like a good way.

Is there a cleaner way to do this in mvc?

+1  A: 

You can store your data in TempData but you don't have to do it that way.

You can have three actions :

[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Edit() {
    //Returns the Edit view that displays an edit form
    //That edit form should post to the same action but with POST method.
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(AccountInformationModel m) {
    //Checks the form data and displays the errors in the 
    //edit view if the form data doesn't validate
    //If it does validate, then returns the Review view which renders 
    //all the form fields again but with their type as "hidden".
    //That form should post to Save action
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Save(AccountInformationModel m) {
    //Checks the form data again (just to be safe in case 
    //the user tampers the data in the previous step)
    //and displays the errors in the edit view if it doesn't validate.
    //if it does validate, saves the changes.
}
çağdaş
TempData is for when you have one action redirect to another action only... http://blogs.teamb.com/craigstuntz/2009/01/23/37947/. The three actions is the way to go though. If you have multiple edit screens then just repeat the second action multiple times returning the next edit view each time. Then on the last edit view return the review view.
Russell Giddings