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>