一个聪明的方式来处理在MVC环境中返回的网址 [英] A smart way to handle Return URLs in an MVC environment

查看:154
本文介绍了一个聪明的方式来处理在MVC环境中返回的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个问题,我遇到了一次又一次的用户运行一些动作,如单击返回到...链接或保存他们正在编辑的记录后,正在处理重定向到previous页面。

A problem I come up against again and again is handling redirection to the previous page after a user runs some action such as clicking a 'Back To ...' link or saving the record they are editing.

previously每当我有需要知道返回的页面,我将提供一个 RETURNURL 参数,以我目前的看法。

Previously whenever I have needed to know what page to return to, I would provide a returnURL parameter to my current view.

http://blah.com/account/edit/1?returnURL="account/index"

这不是处理这种情况,因为有时返回URL中包含的参数,如搜索字符串等,这些都必须包含在URL中一个非常干净的方式。

This isn't a very clean way of handling this situation, as sometimes the return URL contains parameters such as search strings, etc, which have to be included in the URL.

http://blah.com/account/edit/1?returnURL="account/index?search="searchTerm""

此外,这将创建一个问题,当用户可以回来的页面之前,向前走另一页 RETURNURL ,因为你必须要通过 RETURNURL 。

简单地调用浏览器的后退功能是不是真的足够要么,因为你可能想页面刷新,例如展现你刚刚保存在previous页面的编辑。

Simply calling the browser's Back functionality isn't really sufficient either, because you might want the page to refresh, e.g. to show the edits you just saved in the previous page.

所以我的问题是,有没有人发现了一个聪明的方式来处理这种情况,特别是在一个MVC环境?

So my question is, has anyone found a smart way to handle this kind of situation, specifically in an MVC environment?

注意:我使用的ASP .NET MVC所以如果可能的话,我想答案涉及到,但是任何想法,欢迎

Note: I am using ASP .NET MVC so if possible I'd like answers to pertain to that, however any ideas are welcome.

推荐答案

这有什么错设置cookie,或者使用一个会话变量?你会唯一的原因就是没有,如果你不控制调用到你的页面,在这种情况下,你唯一的选择是查询字符串,后期值或引用。

What's wrong with setting a cookie, or using a session variable? The only reason you wouldn't is if you don't control the page that calls into you, in which case your only options are query strings, post values, or referrer.

这篇关于一个聪明的方式来处理在MVC环境中返回的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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