我想在这里修改问题,我的重点是 MVC Url.Action:
我正在Url.Action
测试http:// localhost:22334/Order/Index
@Url.Action("摘要", "订单")
当路由配置为
routes.MapRoute(
name: "Order",
url: "{lang}/Order/{action}",
defaults: new { lang = UrlParameter.Optional, controller = "Order", action = "Index" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{*pathInfo}",
defaults: new { controller = "Order", action = "Index", id = UrlParameter.Optional }
);
它生成一个//Order/Summary
不起作用的链接
但是,当路由配置添加约束时
routes.MapRoute(
name: "Order",
url: "{lang}/Order/{action}",
defaults: new { lang = UrlParameter.Optional, controller = "Order", action = "Index" },
constraints: new { lang = "[a-z]{2}" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{*pathInfo}",
defaults: new { controller = "Order", action = "Index", id = UrlParameter.Optional }
);
它生成一个/Order/Summary
运行良好的链接
- URL.Action 是否取决于路由?
- 由于我在 localhost 上进行测试,当我将 URL.Action 放在服务器上时会产生不同的结果,例如' http://myserver/myapps/ordersystem/Order/Index
谢谢
此致,
薄荷灵魂