A beginner question - I have a HomeController, HomeModel and HomeView. When the user comes to the http://page/Home
page, then Index
method is executed and he can fill out some controls. After he clicks on a button (postback), the Process action is executed and in the case of an error, the application calls the ModelState.AddModelError
method. Then the Index
action is called again and I can display the error on the page.
This works OK, but the problem is that after the postback the new url is http://page/Home/Index
instead of http://page/Home
. Any idea how to prevent this?
PS - I tried this solution but then the new url was something like http://page/Home?...long string of serialized ModelState data...
My Controller:
[HttpGet]
public ActionResult Index(MyModel model)
{
return View(model);
}
[HttpPost]
public ActionResult Process(MyModel model)
{
if (...error...)
{
model.SetErrorState();
ModelState.AddModelError("ProcessError", "error message");
return View("Index", model);
}
else
{
// do something...
model.SetSuccessState();
return View("Index", model);
}
}