views:

33

answers:

1

Is it possible to map a route with MapRoute and specify a generic controller e.g

        context.MapRoute(
            "Dashboard_Edit", // Route name
            "dashboard/edit/{*pagePath}",
            new { controller = "Dashboard`1", action = "edit", pagePath = "home" }
            );
A: 

It is unfortunately not allowed with the default controller factory. The type "Dashboard`1" is for an open generic type and cannot be constructed. In other words, with the default controller factory the only allowed values for "controller" are ones that can fit the following pseudo syntax:

IController c = new SomeControllerType();

The SomeControllerType must be valid (though without the "Controller" suffix or namespace), and it must have a parameterless constructor.

You could always write a custom controller factory that has more advanced functionality and understands how to construct generic types.

Eilon
Okay, thanks for taking your time to answer.
Marcus