如何在MVC中获得上一条路线 [英] How to get the previous route in MVC
本文介绍了如何在MVC中获得上一条路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序需要获取所有重定向的先前视图.我目前有一个父控制器,它将检查并获取当前视图.这很好.我如何获得以前的成绩?
My application needs to obtain the previous view on all redirects. I currently have a parent controller that will check and grabs the current view. This works fine. How do I get previous?
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
String currentView = Request.RawUrl
//Do stuff with currentView string
//String previousView = ......?
//Do stuff with previousView string
var query = db.PageRoutes.Where(a => a.RouteKey == currentView).FirstOrDefault();
if (query != null)
{
ViewBag.htmlRawData = query.Results;
}
base.OnActionExecuting(filterContext);
}
最后,请使用:
String previousUrl = Request.UrlReferrer.AbsoluteUri;
将带回上一页,例如//localhost:53188/Help/Index,我只需要/Help/Index
will bring back the previous page like //localhost:53188/Help/Index where as I just need /Help/Index
推荐答案
String previousUrl = Request.UrlReferrer.AbsolutePath;
这篇关于如何在MVC中获得上一条路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文