如何在ASP.NET MVC3中发布后在不同控制器中显示错误
问题描述:
第一件事,对不起我的英文。如何在ASP.NET MVC3中发布后在不同控制器中显示错误
我在索引中有两种形式。
登录形式将张贴到localhost /帐号/ LogOn支持
登记表将张贴到localhost /帐号/注册
我怎样才能在本地主机/显示错误后网友发帖形式之一?
目前该错误会在本地主机/客户/登录或$本地主机/客户/注册显示
这是我的代码:
#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
基本上LogOn支持行动中的AccountController同样与注册行动
我认为我坚持Return PartialView(user)
我需要返回到HomeController中的索引操作并维护在ModelState中
任何暗示要做到这一点?
答
我认为使用prg(POST-REDIRECT-GET)模式是一种很好的做法,可以帮助您管理您的问题。 modelState通过过滤器导入和导出。
看点没有13这里 http://weblogs.asp.net/rashid/archive/2009/04/01/asp-net-mvc-best-practices-part-1.aspx#prg
我认为这是总是相关的。