I have a view user control that can post form. This control can be used on multiple views. If user enters invalid data i add errors to ModelState - as simple as that. The problem is that i don't know which view/actionresult to return since i don't know from where user post form. Ok, i can get urlreferer - but that does not look nice for me. Any idea?
views:
144answers:
1
+2
Q:
asp.net mvc: How to handle situation when error happens during posting form from view user control?
+1
A:
Pass the info from your parent page to the controller.
<% RenderPartial("MyUserControl", new MyUserControlViewData()
{
// pass parent page info here for user control to redirect to such as
Controller = "Home",
Action = "Index"
// or even better
ParentPath = ((WebFormView)this.ViewContext.View).ViewPath
});
Todd Smith
2008-12-07 02:36:15
thanks - great answer...
michal zygula
2009-01-06 21:56:51