获得previous行动和控制器的名称在MVC控制器 [英] Getting the names of previous action and controller in MVC controller
本文介绍了获得previous行动和控制器的名称在MVC控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以得到当前的动作和控制器一样的名称:
I can get the name of current action and controller like :
string controllername = this.ValueProvider.GetValue("controller").RawValue.ToString();
string actionname = this.ValueProvider.GetValue("action").RawValue.ToString();
我也可以像获得reffer网址:
字符串MyReferrer = Request.UrlReferrer.ToString();
Also I can get the reffer url by something like : string MyReferrer = Request.UrlReferrer.ToString();
但我怎样才能在MVC2控制器previous行动和控制器的名字?
But how can I get the names of previous action and controller in the mvc2 controller?
推荐答案
这应该工作!
var controller = Request.UrlReferrer.Segments
.Skip(1).Take(1).SingleOrDefault() ?? "Home").Trim('/');
// Home is default controller
var action = (Request.UrlReferrer.Segments
.Skip(2).Take(1).SingleOrDefault() ?? "Index").Trim('/');
// Index is default action
这篇关于获得previous行动和控制器的名称在MVC控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文