문제

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" }
            );
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top