MVC相当于ASP.NET按钮单击事件

编程入门 行业动态 更新时间:2024-10-19 20:43:40
本文介绍了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)属于正常区分和调回页面,例如这里:

的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按钮单击事件

本文发布于:2023-11-03 15:27:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555449.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单击   按钮   事件   MVC   ASP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!