0

We have very long multi step form i.e. the user has to fill 20 steps and each step has 5 dropdowns/text fields. At every 4th step, we need to send this data to some external API

[HttpPost]
public ActionResult Step1(Step1to4ViewModel model)
{
    if (ModelState.IsValid)
    {
        Session["Step1"] = model;
        // Hit External API
        return RedirectToAction("Step2");
    }    
    return View(model);  // errors
}

[HttpPost]
public ActionResult StepFinal(Step17To20ViewModel model)
{
    if (ModelState.IsValid)
    {
        var myEntity = new MyEntity();

        var step1 = Session['Step1'] as Step1to4ViewModel;
        // ... similarly for other steps
        var step5 = Session['Step5'] as Step17to20ViewModel;
        myEntity.step1 = step1;
        myEntity.step5 = step5;    

        db.MyEntities.Add(myEntity);
        db.SaveChanges();

        Session.Remove('Step1');
        // repeat for each step in session

        return RedirectToAction("Success");
    }

    // errors
    return View(model);
}

I have following doubts:

  1. Should we use "Session" storage for such a length form?
  2. How "Session" storage is managed? Is it managed on server side OR on client+server side?
  3. I understand benefits of using session storage but is there any downside of using session storage?
Sahil Sharma
  • 3,847
  • 6
  • 48
  • 98
  • 2
    1) with "very long form", "multistep" and "session" in one sentence, your doubts are reasonable. 2) There are at least three options of how session state can be persisted in IIS ([read up on it here](https://msdn.microsoft.com/en-us/library/ms178586.aspx)). Session data is stored server-side and tied to a client session using usually a browser cookie. 3) yes there are downsides - expiration, memory pressure in highly concurrent scenarios. Try to rephrase your questions to be more specific, as it stands it is likely to be closed as too broad or opinion-based. – Cee McSharpface Aug 09 '17 at 21:04
  • 1
    Don't forget about [TempData](https://stackoverflow.com/questions/12422930/using-tempdata-in-asp-net-mvc-best-practice), which is probably preferable to session since it cleans itself up. – John Wu Aug 09 '17 at 21:59

0 Answers0