相关疑难解决方法(0)

ASP.NET MVC 4路由 - 控制器/ id与控制器/动作/ id

我正在尝试将路由添加到默认路由,以便我有两个URL工作:

  1. http://www.mywebsite.com/users/create
  2. http://www.mywebsite.com/users/1

这将使第一条路线起作用:

routes.MapRoute(
     name: "Default",
     url: "{controller}/{action}/{id}",
     defaults: new { controller = "users", action = "Index", id = UrlParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)

但是,第二条路线显然不会起作用.

这将使第二条路线起作用,但会破坏第一条路线:

routes.MapRoute(
     name: "Book",
     url: "books/{id}",
     defaults: new { controller = "users", action = "Details" }
);
Run Code Online (Sandbox Code Playgroud)

如何组合两个路由配置,以便两个URL都有效?如果在SO上已经存在这样的问题我很抱歉,我无法找到任何东西.

asp.net-mvc routes asp.net-mvc-routing asp.net-mvc-4

17
推荐指数
1
解决办法
3万
查看次数