Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取RouteConfig.RegisterRoutes()中的控制器名称_C#_Asp.net Mvc_Asp.net Mvc 5 - Fatal编程技术网

C# 获取RouteConfig.RegisterRoutes()中的控制器名称

C# 获取RouteConfig.RegisterRoutes()中的控制器名称,c#,asp.net-mvc,asp.net-mvc-5,C#,Asp.net Mvc,Asp.net Mvc 5,每个人都知道静态RouteConfig.RegisterRoutes()方法中的那些语句: routes.MapRoute( "Teasers", "Teasers/{action}/{id}", new { controller = "Teasers", action = "Index", id = 0 } ); 但这不是很安全。另一种不切实际的选择是: var teasers = nameof(TeasersController).Replace("Cont

每个人都知道静态
RouteConfig.RegisterRoutes()方法中的那些语句:

routes.MapRoute(
    "Teasers",
    "Teasers/{action}/{id}",
    new { controller = "Teasers", action = "Index", id = 0 }
    );
但这不是很安全。另一种不切实际的选择是:

var teasers = nameof(TeasersController).Replace("Controller", "");
routes.MapRoute(
    teasers,
    teasers + "/{action}/{id}",
    new {controller = teasers, action = "Index", id = 0}
);

有什么优雅的东西吗?

搜索internets@Luke是的。Google以及我在按键时宣布的所有建议。有一个是针对ASP.NET MVC Core的>>当然,你需要在Core中开发,而不是原始版本one@Luke谢谢那是个好工具。当我们升级到ASP.NET MVC核心时,我会考虑它。看起来是同一个开发出来的,不用费心为原来的ASP.NET MVC开发它,而是觉得它必须与核心版本兼容。我想知道为什么。。。