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

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

问题描述

在ASP.NET MVC中有一种方法可以通过代码枚举控制器并获取其名称?

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

示例:

AccountController
HomeController
PersonController


$ b b

会给我一个列表,例如:

would give me a list such as:

Account, Home, Person


推荐答案

您可以反映您的程序集并找到继承System.Web.MVC类的所有类。控制器。下面是一些示例代码,显示了如何做:

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天全站免登陆