我在RouteConfig.cs 中有一个自定义路由
routes.MapRoute(
"Category3",
"category/{action}/{top}/{middle}/{category}",
new { controller = "Category", action = "Index", top = UrlParameter.Optional, middle = UrlParameter.Optional, category = UrlParameter.Optional }
);
我的分类控制器看起来像
public class CategoryController : Controller
{
//
// GET: /Category/
public string Get(string top, string middle, string category)
{
return top + "/" + middle + "/" + category;
}
}
一切正常
/category/get/1/2/3 gives output 1/2/3
/category/get/1/2 gives output 1/2
但是
/category/get/1 gives output ""
我如何映射一条路线,它会给最后一个url输出1?
最终目标是获得类似的URL
/category/get/main/sub/category
如有任何帮助,我们将不胜感激。
此路由是否低于默认路由?如果是这样,那么您可能正在执行Index
操作。路线按从上到下的顺序进行处理,第一场比赛获胜。