First thing, sorry for my English.
I have two forms in index.
Login form will post to localhost/Account/LogOn
Register form will post to localhost/Account/SignUp
How can I display error in localhost/ after user post one of the form ?
Currently the error will display in localhost/Account/LogOn or localhost/Account/SignUp
These are my codes:
#Index Action in HomeController
Public Function Index() As ActionResult
Return PartialView("_default")
End Function
#_default layout
<html>
<head></head>
<body>
@code
Html.RenderAction("SignUp", "Account")
End Code
@code
Html.RenderAction("LogOn", "Account")
End Code
</body>
</html>
#SignUp Action in AccountController
Public Function SignUp() As ActionResult
Return PartialView()
End Function
<HttpPost()> _
Public Function SignUp(user As UserView) As ActionResult
If ModelState.IsValid Then
'some process
Return RedirectToAction("Welcome", "Home")
Else
ModelState.AddModelError("", "Email already taken")
End If
Return PartialView(user)
End Function
Basically LogOn Action in AccountController same with SignUp Action
I think I’m stuck with the Return PartialView(user)
I need to return to Index Action in HomeController and maintain the ModelState
Any hint to do this?
I think that usage of prg (POST-REDIRECT-GET) pattern is a good practice, and can help you in managing your problem. The modelState is imported and exported with filters.
Look at the point no 13 here
http://weblogs.asp.net/rashid/archive/2009/04/01/asp-net-mvc-best-practices-part-1.aspx#prg
I think it’s always relevant.