Wednesday, 15 May 2013

Creating a Wizard with Friendly URLs in ASP.NET MVC 4 -



Creating a Wizard with Friendly URLs in ASP.NET MVC 4 -

i'm working on asp.net mvc 4 app. app requires wizard within it. wizard contains 3 screens. need urls map to:

/wizard/step-1 /wizard/step-2 /wizard/step-3

in wizardcontroller, have next actions:

public actionresult step1() { var model = new step1model(); homecoming view("~/views/wizard/step1.cshtml", model); } [httppost] public actionresult addstep1(step1model previousmodel) { var model = new step2model(); model.somevalue = previousmodel.somevalue; homecoming view("~/views/wizard/step2.cshtml", model); } [httppost] public actionresult addstep2(step2model previousmodel) { var model = new step3model(); homecoming view("~/views/wizard/step3.cshtml", model); }

while approach works, problem browser url doesn't update. how post values step , redirect user new url different info model?

thank you!

in each of wizard's views phone call html.beginform(), create sure phone call overload of accepts either desired route, or desired controller, action, , other routing parameters. example, in step1.cshtml:

@using (html.beginform("step-2", "mywizard")) { // set view stuff in here step #1, post step #2 }

that create target url "pretty", won't prepare action names beingness "ugly". prepare that, there's feature in mvc "rename" action method want:

[httppost] [actionname("step-2")] // create effective name of action "step-2" instead of "addstep1" public actionresult addstep1(step1model previousmodel) { // code here }

assuming app using default mvc route (controller/action/id), each step have own url.

asp.net-mvc-4 wizard

No comments:

Post a Comment