1

ASP.NET MVC 框架中是否有代表控制器名称和操作名称的类?

我正在编写一个返回 URL 集合的方法,我希望它们作为包含“Controller”和“Action”属性或类似属性的对象返回。

这是因为有时我只需要隔离控制器名称或操作名称。

有 Route 对象,但对于我正在尝试做的事情来说,它似乎太重了。

ASP.NET MVC 中是否有更简单的抽象?

4

1 回答 1

2

There is a Controller Base class not a name though, an action name is simply an string which the ActionInvoker will use to find the correct action via reflection.

I think you'll have to use the Route Values Dictionary of key/value pairs to represent the route.

RouteValueDictionary myValues = new RouteValueDictionary();
myValues.Add("Controller", "myController");

You could use a normal dictionary and then convert it in code to a RouteValueDictionary if you don't want/can't have to have access to the Routing namespace.

In this approach you can then using the keys of the either a standard dictionary or the routeValue Dictionary to do the isolation of the controller or action.

String ControlString = myValues["Controller"] 

Then do what you want with it. Maybe use constants for the keys you wish to access.

于 2009-08-05T07:48:43.027 回答