ASP.NET MVC编程方式获取控制器列表 [英] ASP.NET MVC Programatically Get a List of Controllers

查看:99
本文介绍了ASP.NET MVC编程方式获取控制器列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP.NET MVC是有办法通过列举code中的控制器,并得到他们的名字吗?

例如:

 的AccountController
HomeController的
PersonController

会给我一个名单,如:

 帐户,家庭,人


解决方案

您可以通过您的程序集反映,找到从类型System.Web.MVC.Controller继承的所有类。下面是一些示例code,告诉您如何能做到这一点:

<一个href=\"http://mvcsitemap.$c$cplex.com/WorkItem/View.aspx?WorkItemId=1567\">http://mvcsitemap.$c$cplex.com/WorkItem/View.aspx?WorkItemId=1567

In ASP.NET MVC is there a way to enumerate the controllers through code and get their name?

example:

AccountController
HomeController
PersonController

would give me a list such as:

Account, Home, Person

解决方案

You can reflect through your assembly and find all classes which inherit from type System.Web.MVC.Controller. Here's some sample code that shows how you could do that:

http://mvcsitemap.codeplex.com/WorkItem/View.aspx?WorkItemId=1567

这篇关于ASP.NET MVC编程方式获取控制器列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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