我要创建具有等同于ASP.NET按钮的Click事件的页面。
在我的网页,当用户点击一个按钮,我需要处理一些信息,如果发生错误则显示错误页面,但如果它是成功的,我需要一个显示页面成功。我是新的MVC和我不知道如何去这个...
这就是我想出了至今(不知道这是否会甚至工作),我会创造一个ActionResult函数来处理信息,然后有功能决定应显示的网页...
'//富页函数foo(BYVAL参数1字符串,BYVAL参数2为String)作为的ActionResult 返回查看()结束功能功能FooProcess(BYVAL参数1字符串,BYVAL参数2为String)作为的ActionResult '//查找信息和流程 '// bSuccess =过程(参数1,参数2) //如果bSuccess然后 '//重定向到成功页面 '//其他 '//重定向到错误页面 '//万一结束功能功能FooSuccessful()为的ActionResult 返回查看()结束功能功能FooError(BYVAL味精作为字符串)作为的ActionResult 返回查看()结束功能解决方案
您需要使用的[AcceptVerbs(HttpVerbs.Post)]和的[AcceptVerbs(HttpVerbs.Get)属于正常区分和调回页面,例如这里:
的blog.jorritsalverda.nl/2010/03/10/maintainable-mvc-post-redirect-get-pattern/
I need to create a page that has the equivalent to button click event in ASP.NET.
On my page when the user clicks a button I need to process some information and if an error occured then display an Error page, but if it was successful I need to display a successful page. I'm new at MVC and I'm not sure how to go about this...
This is what I've came up with so far (don't know if this will even work), I would create an ActionResult function to process the information then have the function decide which page should be displayed...
'//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解决方案
you need to use [AcceptVerbs(HttpVerbs.Post)] and [AcceptVerbs(HttpVerbs.Get)] attributes to distinguish between normal and posted back page as for example here:
blog.jorritsalverda.nl/2010/03/10/maintainable-mvc-post-redirect-get-pattern/
更多推荐
MVC相当于ASP.NET按钮单击事件
发布评论