在MVC3,如何让当前的控制器名? [英] In MVC3, how to get the current controller name?

查看:99
本文介绍了在MVC3,如何让当前的控制器名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从HTTP上下文类是那里得到电流控制器名称的方法?

From the http context class is there a method to get the current Controller name?

推荐答案

是的,你可以做这样的事情。

Yes, you can do something like that

HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString();

如果你在一个视图中,那么你可以做:

If you're in a view, then you can do:

ViewContext.RouteData.Values["Controller"]

这篇关于在MVC3,如何让当前的控制器名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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