I am new to MVC and I will try to elaborate my issue carefully. I have a controller with 2 Action Methods, one of which is a POST method:
[AllowAnonymous]
public ActionResult Register()
{
RegisterViewModel registerModel = new RegisterViewModel();
//Some Code to populate dropdowns for user to select
return View(registerModel);
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
try
{
if (ModelState.IsValid)
{
//insert data in tables
RedirectToAction("Register");
}
AddErrors(result);
}
catch (Exception ex)
{
ModelState.AddModelError("", "Error Processing Your Request");
}
// If ModelState.IsValid returns false show the form with posted data by user
return RedirectToAction("Register", model);
}
Now when form is posted all the data filled by user is not persisted. I want to display the same form to user with his posted data and fill missing details to complete registration.
Sorry if this is a very basic question. How do I persist the data on the same view.