我想将ASP MVC
(controller/action/id
)的默认路由更改为
course-categories/view/1 to course-categories/1
course-categories/edit/1 to course-categories/1/edit
尝试了这个
context.MapRoute(
name: "ControlPanel.CourseCategory",
url: "controlpanel/course-categories/{id}/{action}",
defaults: new { controller = "CourseCategory", action = "View", id = UrlParameter.Optional },
namespaces: new[] { "Website.Areas.ControlPanel.Controllers" }
);
课程 - 类别/创建现在无法映射或课程类别/ {action}
答案 0 :(得分:0)
由于您将ID放在路径中并使其成为可选项,同时也是该操作的默认值,因此我会对ID进行约束以避免路由冲突。
context.MapRoute(
...
constraints: new { id = @"(\d)+" }
);