MVC相当于ASP.NET按钮单击事件 [英] MVC equivalent to ASP.NET Button Click Event

查看:95
本文介绍了MVC相当于ASP.NET按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建具有等同于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)属于正常区分和调回页面,例如这里:

http://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:

http://blog.jorritsalverda.nl/2010/03/10/maintainable-mvc-post-redirect-get-pattern/

这篇关于MVC相当于ASP.NET按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆