views:

84

answers:

3

What is the ultimate workaround?)

Desired scenarios are:

  1. Multistep forms.
  2. If a page has tabs on it, the tabs should persist their `viewstate'
  3. Whatever navigation user has chosen, it shouldn't affect (more appropriately, bother) the conversational state management.

Those are just several aspects, but I find them much practically relevant.

+1  A: 

I have worked once on Wizard kind of form in Asp.Net MVC and best thing to do in this case is to use Model/ModelBinding to keep track of form input.

We can create a chain of Controller Actions (for each steps) with output model of each serving as the input Model for the next Step (Action).

For example if we have three steps for creating a user. Then UserController can have actions for each steps.

public ActionResult Step1()
{
   User user = new User();
   return View(user);
}

[Post]
public ActionResult Step1(User user)
    {
       //perform business validation
        RedirectToAction<UserController>(u => Step2(user)); 

    }

After this Step2 action will take over with modified user from Step1 and can render its own view and so on.

Amitabh
+1  A: 

You may also want to check out http://blog.maartenballiauw.be/post/2009/10/08/Leveraging-ASPNET-MVC-2-futures-ViewState.aspx. There's an Html.Serialize() helper in MVC Futures. The article refers to it as lightweight Viewstate, but it's effectively just a glorified wrapper around "serialize this object and store the base64 string in a hidden form field." If you need state to be associated with individual pages rather than an entire Session, this helper might be appropriate for your needs.

Levi
+1  A: 

Not sure about a "workaround", but have you considered using AJAX and jQuery? Both would be appropriate based on the requirements you listed.

James H
Wish I never use AJAX and JavaScript, but +1 for mention of the standart fallback option :)
Bubba88