multi-step registration process issues in asp.net mvc (split viewmodels, single model)

后端 未结 7 1149
走了就别回头了
走了就别回头了 2020-11-22 17:08

I have a multi-step registration process, backed by a single object in domain layer, which have validation rules defined on properties.

7条回答
  •  春和景丽
    2020-11-22 17:17

    I would suggest you to maintain the state of Complete Process on the client using Jquery.

    For Example we have a Three Step Wizard process.

    1. The user in presented with the Step1 on which has a button Labeled "Next"
    2. On Clicking Next We make an Ajax Request and Create a DIV called Step2 and load the HTML into that DIV.
    3. On the Step3 we have a Button labeled "Finished" on Clicking on the button post the data using $.post call.

    This way you can easily build your domain object directly from the form post data and in case the data has errors return valid JSON holding all the error message and display them in a div.

    Please split the Steps

    public class Wizard 
    {
      public Step1 Step1 {get;set;}
      public Step2 Step2 {get;set;}
      public Step3 Step3 {get;set;}
    }
    
    public ActionResult Step1(Step1 step)
    {
      if(Model.IsValid)
     {
       Wizard wiz = new Wizard();
       wiz.Step1 = step;
      //Store the Wizard in Session;
      //Return the action
     }
    }
    
    public ActionResult Step2(Step2 step)
    {
     if(Model.IsValid)
     {
       //Pull the Wizard From Session
       wiz.Step2=step;
     }
    }
    

    The Above is just a demonstration which will help you achieve the end result. On the Final Step you have to create the Domain Object and populate the correct values from the Wizard Object and Store into the database.

提交回复
热议问题