Tuesday, January 30, 2018

[Help\Comment] Creating a Multistep Form

I'm trying to reproduce a multistep form that uses multiple submissions instead of a javascript solution. I have created a simple view model called WizardViewModel with two properties PersonalInfoViewModel and ContactInfoViewModel (each representing a step in the form). My controller is attached below; while it seems to work great, I'm looking for input as to whether or not this is a good approach. Cheers and thanks in advance!

namespace DataBetweenControllers.Controllers { public class WizardController : Controller { public static WizardViewModel WizardViewModel {get; set;} public IActionResult Index() { return View(); } [HttpPost] public IActionResult Contact(PersonalInfoViewModel personalInfoViewModel) { if (!ModelState.IsValid) { return RedirectToAction("Index"); } WizardViewModel = new WizardViewModel { PersonalInfo = personalInfoViewModel }; return View(); } [HttpPost] public IActionResult Review(ContactViewModel contactViewModel) { if (!ModelState.IsValid) { return RedirectToAction("Index"); } WizardViewModel.ContactInfo = contactViewModel; return View(WizardViewModel); } // User should not be able to access any of the actions via GET [HttpGet] public IActionResult Contact() => RedirectToAction("Index"); [HttpGet] public IActionResult Review() => RedirectToAction("Index"); } } 
[Help\Comment] Creating a Multistep Form Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team