TiagoDias
TiagoDias

Reputation: 1865

ASP.NET MVC Wizard kind of logic

I have a wizard kind of issue to solve in my MVC application. I have no Javascript and i have 3 Views, one for each step.

The scenario is: I have a 3 step process. S1 posts to S2 and S2 posts to S3. If i have a model validation error, the error is catched on the next view because the data was already posted there. My code looks like: return(View, modeldata) if ok ELSE return ("PreviousView", modeldata). The problem is my URL that remains in the post url requested

Upvotes: 0

Views: 285

Answers (1)

Fenton
Fenton

Reputation: 251282

In all cases I would post each form back to the original controller / action and then forward to the appropriate next step... i.e.

[HttpGet]
public ActionResult StepOneNameHere() {
    StepOneModel model = new StepOneModel();

    // Populate any bits on the model...
    return View(model);
}

[HttpPost]
public ActionResult StepOneNameHere(StepOneModel model) {
    // Validation

    if (ModelState.IsValid) {
        // You can add logic to choose the next step, for example if they have
        // selected an option that requires an additional step in the wizard or
        // if you can skip a step in the wizard
        return RedirectToAction("StepTwoNameHere");
    } else {
        return View(model);
    }
}

Upvotes: 3

Related Questions