通过操作过滤器注入引荐来源网址操作?
有没有办法从操作过滤器注入引用者操作? 假设我有一个来自操作 X 的视图。在模具视图中,我调用操作 Y,并且我想再次重定向到操作 X。(有多个 X 操作调用操作 Y)。我认为如果我有一个参数调用referrerAction 和一个用前一个操作填充它的操作过滤器,那就太好了。是否可以?
谢谢。
Is there a way to inject the referrer action from an action filter?
Lets say I have a view that comes from action X. In dies view I call action Y and I want to redirect again to action X. (There are multiple X actions that call action Y). I thought that it could be nice if I had a parameter call referrerAction and an action filter that filled it with the previous action. Is it possible?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我是这样做的:
现在,您用 [ReturnPoint] 标记 X 个操作,如果您想返回,则调用 RedirectOrReturn() 。
我不使用 UrlReferrer,因为它可能是错误的,而且我无法控制它的值。使用 ReturnPoint,您还可以拥有组,例如 [ReturnPoint("Orders")] 和 RedirectOrReturn("Orders")。
当然,您可以在 OnActionExecuted 中拥有更多自动行为 - 例如,它可以检查返回结果是否为 Redirect,如果有值则自动转到 ReturnPoint。或者您可以使用 [ReturnPoint(Automatic=true)] 等来控制。
Here's how I do:
Now, you mark you X actions with [ReturnPoint] and call RedirectOrReturn() if you want to return back.
I do not use UrlReferrer because it can be wrong and I have no control over its value. With ReturnPoint, you can also have groups, e.g. [ReturnPoint("Orders")] and RedirectOrReturn("Orders").
Of course, you can have more automatic behaviour in OnActionExecuted - e.g. it can check if returned result is Redirect, and automatically go to ReturnPoint if it has value. Or you can control this with [ReturnPoint(Automatic=true)], and so on.