我试图在控制器名称后的mvc中传递参数
我加了
routes.MapRoute(
name: "Product",
url: "Product/{*id}",
defaults: new { controller = "Product", action = "Index", id = UrlParameter.Optional }
);
这没用
我也试过了 url: "Product/{id}",
但是如果我删除上面的线(这篇文章下面的线),它正在工作
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
您注册路线的顺序很重要。使用与请求匹配的第一条路线。如果我理解正确,那么您最初有:
routes.MapRoute(
name: "Default",
...
routes.MapRoute(
name: "Product",
默认路线非常通用,并且因为它是首先注册的,所以它一直为您的所有请求所使用,有效地掩盖了产品路线。
正确的注册路由方法是从最具体的路由开始,并在末尾注册最通用的路由。因此,在您的情况下,应将其反转:
routes.MapRoute(
name: "Product",
...
routes.MapRoute(
name: "Default",
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句