我需要创建一个与 ASP.NET 中的按钮单击事件等效的页面。
在我的页面上,当用户单击按钮时,我需要处理一些信息,如果发生错误,则显示错误页面,但如果成功,我需要显示成功页面。我是 MVC 的新手,我不知道如何解决这个问题......
这就是我到目前为止所想到的(不知道这是否有效),我将创建一个 ActionResult 函数来处理信息,然后让该函数决定应该显示哪个页面......
'//Foo page
Function Foo(Byval param1 as String, Byval param2 as String) As ActionResult
Return View()
End Function
Function FooProcess(Byval param1 as String, Byval param2 as String) As ActionResult
'//Look up information and process
'//bSuccess = process(param1, param2)
'//If bSuccess Then
'// redirect to successful page
'//else
'// redirect to error page
'//end if
End Function
Function FooSuccessful() As ActionResult
Return View()
End Function
Function FooError(ByVal msg As String) As ActionResult
Return View()
End Function
您需要使用 [AcceptVerbs(HttpVerbs.Post)] 和 [AcceptVerbs(HttpVerbs.Get)] 属性来区分正常页面和回传页面,例如:
http://blog.jorritsalverda.nl/2010/03/10/maintainable-mvc-post-redirect-get-pattern/ http://blog.jorritsalverda.nl/2010/03/10/maintainable-mvc-post-redirect-get-pattern/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)