当我创建一个名为“home-solutions”的 Controller 时,主类更改为 home_solutionsController
。 '-' 被替换为 '_'。
localhost/home-solutions
此外,当我调用 localhost/home-solutions 时,它显示“找不到资源。”
如何创建名称中带有“-”的 Controller 并调用它?
最佳答案
Controller 名称中不能包含“-”。
但是,如果您真正需要的是在 URL 中支持 home-solutions
,您可以有一个映射到某个 Controller (使用其他名称)的自定义路由,例如:
routes.MapRoute(
"HomeSolutionsRoute",
"home-solutions/{action}/{id}",
new { controller = "HomeSolutions", action = "Index", id = UrlParameter.Optional }
);
关于c# - Asp.net MVC 路由名称带有 '-',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29979883/