I am using two actions one for the get portion of my request (a generic looking url) and another for the post.
In the case that a post has ModelState errors, I would like to view to return to show the errors but I would like the url to be the generic url.
So this is what currently happens:
Get: http://foo.com/mycontroller
Post: http://foo.com/mycontroller/specificviewaction (validation error occurs)
Resultant url is: http://foo.com/mycontroller/specificviewaction
Where as I want it to be http://foo.com/mycontroller the appropriate errors.
Here is my current code:
public ActionResult Index()
{
// ... do stuff
return View("specificviewaction ", model);
}
[HttpPost]
public ActionResult specificviewaction(Model model)
{
if (ModelState.IsValid)
{
// ... do stuff
}
return View("specificviewaction", model);
}
Note, there is no actual Index view, only specific views.
This is what I ended up doing.
I left the routing table as per the default implementation.
Then for each model type, I am putting a hidden field in the form with which type it is.
On the post, I check what type it is and use
TryUpdateModelto update an instance of the model with the correct form values.If it succeeds great, if not I can deliver the appropriate errors back.
I was trying to over think it, simplest approach was best.