1

I want to create Multi-Step form in Asp.Net Core. Each step will do a request to the server. I have code that will render first step. I also want to pass the form to the next action. I couldn't pass the step 1 data, all I get is the form with null. How do I pass the step 1 data to step 2?

Model

public class FLHAForm
{
    public string Work { get; set; }
    public string Location { get; set; }
    [DisplayName("Muster Point")]
    public string MusterPoint { get; set; }
    [DisplayName("Permit Job")]
    public string PermitJob { get; set; }
    [DisplayName("PPE Inspected")]
    public string PPEInspected { get; set; }
}

Controller

[HttpGet("FLHA/Step1")]
public IActionResult Step1()
{
    FLHAForm form = new FLHAForm();
    return View(form);
}

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult CreateStep1(FLHAForm form)
{
    return RedirectToAction("Step2", "FLHA", form);
}

[HttpGet("FLHA/Step2")]
public IActionResult Step2(FLHAForm form)
{
    return View(form);
}

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult CreateStep2(FLHAForm form)
{
    return RedirectToAction("Index");
}

View

@model DBI.Safety.Models.FLHAForm

@{
   ViewData["Title"] = "Field Level Hazard Assessment";
}


<div class="row">
   <div class="col-md-12">
     <form asp-action="CreateStep1">
          Step 1 content...
     </form>
   </div>
</div>
dsub camfx
  • 21
  • 1
  • 5
  • 1
    @Html.HiddenFor() or just do it in one form (show and hide based on step) – Steve May 25 '18 at 19:31
  • Possible duplicate of https://stackoverflow.com/questions/39381443/asp-net-mvc-persisting-data-across-multiple-wizard-steps-using-database-tables – ernesthm May 25 '18 at 19:53
  • Well I can get the Step 1 form with the current code. All I want is to redirect Step 2 Action with the same form. Is it doable? – dsub camfx May 29 '18 at 12:26
  • @dsub camfx are you still looking for an answer to this question? I used jquery ajax forms and passed partial views. This way I only have one controller action for all form submits. – BoMerican Apr 19 '21 at 12:45

0 Answers0