asp.net mvc - MVC Wizard Issues -


i attempting create wizard in mvc. because need submit stuff db after each step, pass data controller instead of handling client side. cannot life of me figure out doing wrong though. have containing viewmodel viewmodels each of steps , stepindex keep track of at. each of step pages typed containing viewmodel. reason when increment stepindex shows incremented in controller, never kept. have hidden value it, , step1 value passed. have tried model.stepindex++ , model.stepindex + 1, both show in controller incremented when view loaded incorrect value used. turned off caching see if cause. please let me know if see doing wrong. thank you, tj

containing view model

public class wizardvm {     public wizardvm()     {         step1 = new step1vm();         step2 = new step2vm();         step3 = new step3vm();     }      public step1vm step1 { get; set; }     public step2vm step2 { get; set; }     public step3vm step3 { get; set; }     public int stepindex { get; set; } } 

step2 view

@model wizardtest.viewmodel.wizardvm  @{     viewbag.title = "step2"; }  <h2>step2</h2>  @using (html.beginform()) {     @html.validationsummary(true)      @html.hiddenfor(model => model.step1.foo)     @html.hiddenfor(model => model.stepindex)         <fieldset>         <legend>step2vm</legend>           <div class="editor-label">             @html.labelfor(model => model.step2.bar)         </div>         <div class="editor-field">             @html.editorfor(model => model.step2.bar)         </div>          <p>             <input type="submit" value="create" />         </p>     </fieldset> } 

controller

    public actionresult index()     {         var vm = new wizardvm             {                 step1 = { foo = "test" },                  stepindex = 1             };          return view("step1", vm);     }      [outputcache(nostore = true, duration = 0, varybyparam = "*")]     [httppost]     public actionresult index(wizardvm model)     {         switch (model.stepindex)         {             case 1:                 model.stepindex = model.stepindex + 1;                 return view("step2", model);             case 2:                 model.stepindex = model.stepindex + 1;                 return view("step3", model);             case 3:                 //submit here                 break;         }          //error on page         return view(model);     } 

inspect step2 page in browser , view value of hidden field ensure has value of 2.

put break point in index(wizardvm) inspect see value of 2 being posted in step2. there cases previous value restored model data. need call modelstate.clear() or .remove("proeprtyname")

this allow narrow down problem is.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -