的ActionResult返回给调用它页 [英] ActionResult return to page that called it

查看:74
本文介绍了的ActionResult返回给调用它页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ActionLink的,调用我的公众的ActionResult,我想它回返回的页面,它是从所谓的,但如何?

I have a ActionLink, that calls my public ActionResult, and I would like it to return back to the page that it was called from, but how?

推荐答案

有一些技巧,你可以利用这一点。

There are a couple of tricks that you can use for this.

最简单的是...

return Redirect(HttpContext.Request.UrlReferrer.AbsoluteUri);

绝对URI可能不会给你你正在寻找的确切路径,但UrlReferrer应该有你要找的imformation。重定向回报的ActionResult的子类,所以它是一个有效的返回值。

AbsoluteUri may not give you the exact path you are looking for, but UrlReferrer should have the imformation you are looking for. Redirect returns a subclass of ActionResult so it is a valid return value.

另一个想法是立足重定向位置了存储的值。当你打算让多个请求要重定向之前,当您验证一个表单并在第一个反应显示验证问题,如这是很有用的。另一种情况将是当引用不是本地网站。在这两种情况下,你的推荐人不会是你希望它是什么,你将需要从其他地方获取正确的位置。

Another idea is to base the redirect location off of stored values. This is useful when you are going to make multiple requests before you want to redirect, such as when you validate a form and show validation issues on the first response. Another situation will be when the referrer is not a local site. In either case, your referrer won't be what you want it to and you will need to retrieve the correct location from somewhere else.

具体实施方案包括使用隐藏的输入字段的形式,会话状态的,从你的路由数据拉descriminator值,甚至只是一个较恒定的值一样HttpContext.Request.ApplicationPath。

Specific implementations include using a hidden input field on your form, session state, pulling a descriminator value from your route data, or even just a more constant value like HttpContext.Request.ApplicationPath.

祝你好运。

这篇关于的ActionResult返回给调用它页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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