返回按钮或导航到特定视图(页面)-ASP.NET MVC3 [英] Back button or Navigate To Specific View(Page) -ASP.NET MVC3

查看:81
本文介绍了返回按钮或导航到特定视图(页面)-ASP.NET MVC3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将ASP.NET MVC3用于我的Web应用程序.要在用户界面中显示按钮,我在View1.cshtml中使用以下html.

I am using ASP.NET MVC3 for my web application. To display a button in the User Interface I am using the following html in my View1.cshtml.

   <div class="demo">
                    <input type="submit" value="Save" title="Click here to create a comment" />
                    <input type="button" value="Cancel" onclick="location.href='/'"  title="Click here to cancel and go back to main menu" />
 </div>

我想放置一个按钮,以便用户可以返回上一页..为此,我想在.cshtml中放置一个按钮,该按钮需要使用视图名称"并且可以

I want to place a button so that users can go back to the previous page.. So to achieve this I want to place a button in the .cshtml which takes View Name and can

  • 转移到特定视图. (或)
  • 返回上一个视图.

以上任何一项要求都将对我的应用程序有益.

Any one above requirements will be good for my application.

我该怎么做?任何帮助或想法对我都会有用.

How can I do this? Any help or ideas will be useful to me.

谢谢

推荐答案

如果您想将用户发送到他们的上一页,则始终可以在控制器中使用Request.UrlReferrer,但是请注意,他们可能会欺骗此用户很容易另一种方法是为用户存储会话中的上一个位置,然后您可以检索它并将其挂接到视图中的按钮上.

If you want to send the user to their previous page, you can always use Request.UrlReferrer in your controller, but beware that it's possible for them to spoof this quite easily. Another way would be to store the previous location in the session for the user, then you could retrieve it and hook it up to the button in your view.

关于想要按钮,请看这里:

As for wanting a button, take a look here: Html.ActionLink as a button or an image, not a link

请注意,是否确实需要添加后退按钮?大多数浏览器都内置了它们;-)

Mind you, is it really necessary to add a back button? Most browsers have them built in ;-)

这篇关于返回按钮或导航到特定视图(页面)-ASP.NET MVC3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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