I have a multi-step registration process, backed by a single object in domain layer, which have validation rules defined on properties.
Adding more info from @Darin's answer.
What if you have separate design style for each steps and wanted maintain each in separate partial view or what if you have multiple properties for each step ?
While using Html.EditorFor
we have limitation to use partial view.
Create 3 Partial Views under Shared
folder named : Step1ViewModel.cshtml , Step3ViewModel.cshtml , Step3ViewModel.cshtml
For brevity I just posting 1st patial view, other steps are same as Darin's answer.
Step1ViewModel.cs
[Serializable]
public class Step1ViewModel : IStepViewModel
{
[Required]
public string FirstName { get; set; }
public string LastName { get; set; }
public string PhoneNo { get; set; }
public string EmailId { get; set; }
public int Age { get; set; }
}
Step1ViewModel.cshtml
@model WizardPages.ViewModels.Step1ViewModel
Personal Details
@Html.TextBoxFor(x => x.FirstName)
@Html.TextBoxFor(x => x.LastName)
@Html.TextBoxFor(x => x.PhoneNo)
@Html.TextBoxFor(x => x.EmailId)
Index.cshtml
@using Microsoft.Web.Mvc
@model WizardPages.ViewModels.WizardViewModel
@{
var currentStep = Model.Steps[Model.CurrentStepIndex];
string viewName = currentStep.ToString().Substring(currentStep.ToString().LastIndexOf('.') + 1);
}
Step @(Model.CurrentStepIndex + 1) out of @Model.Steps.Count
@using (Html.BeginForm())
{
@Html.Serialize("wizard", Model)
@Html.Hidden("StepType", Model.Steps[Model.CurrentStepIndex].GetType())
@Html.Partial(""+ viewName + "", currentStep);
if (Model.CurrentStepIndex > 0)
{
}
if (Model.CurrentStepIndex < Model.Steps.Count - 1)
{
}
else
{
}
}
If there some better solution, please comment to let others know.