MVC4 - 我的自定义路由不起作用

时间:2013-07-29 17:33:43

标签: asp.net-mvc-4 asp.net-mvc-routing

所以我在下面的MVC4网络应用程序中有一个自定义路线:

routes.MapRoute(
            name: "SecondarySportsCategoryLanding",
            url: "sports/{name}/{id}",
            defaults: new { controller = "FrontCategoriesController", action = "Sports", name = UrlParameter.Optional, id = UrlParameter.Optional }
        );

我也把它置于我的默认值之上。发生的事情是当我去/体育时我得到这个错误:

  

描述:HTTP 404.您正在查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。请查看以下网址,确保拼写正确。

请求的网址:/ sports

我指定了控制器,在里面我有一个名为Sports with 2 with optional参数的Action(默认为null)。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

controller = "FrontCategoriesController"应为controller = "FrontCategories"

因为框架会自动将Controller插入到您的值中。