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

查看:60
本文介绍了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

会给我一个清单,例如:

would give me a list such as:

Account, Home, Person

推荐答案

您可以反映出您的程序集并找到所有继承自System.Web.MVC.Controller类型的类.以下是一些示例代码,展示了如何执行此操作:

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