带有通用控制器的 MapRoute
是否可以使用 MapRoute 映射路线并指定通用控制器,例如
context.MapRoute(
"Dashboard_Edit", // Route name
"dashboard/edit/{*pagePath}",
new { controller = "Dashboard`1", action = "edit", pagePath = "home" }
);
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" }
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,默认控制器工厂不允许这样做。类型“Dashboard`1”是开放泛型类型,无法构造。换句话说,使用默认控制器工厂时,“controller”唯一允许的值是符合以下伪语法的值:
SomeControllerType
必须有效(尽管没有“Controller”后缀或命名空间) ,并且它必须有一个无参数构造函数。您始终可以编写一个具有更高级功能并了解如何构造泛型类型的自定义控制器工厂。
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:
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.