views:

86

answers:

1

Is there a class in the ASP.NET MVC framework that represents a controller name and an action name?

I'm writing a method that will return a collection of URLs and I want them to be returned as objects that contain a 'Controller' and 'Action' property or something similar.

This is because sometimes I'll need to isolate just the controller name or just the action name.

There's the Route object, but it seems way too heavyweight for what I'm trying to do.

Is there a simpler abstraction in ASP.NET MVC?

+2  A: 

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.

Damien