gpt4 book ai didi

c# - MVC URL 模式中的 OR 运算符

转载 作者:太空宇宙 更新时间:2023-11-03 21:35:04 26 4
gpt4 key购买 nike

我正在编写一个 MVC 路由,我想知道,我可以在其中使用类似 OR 运算符的东西吗?

像这样,我的 Urls 可以以“shop/”或“articles/”开头吗?

        routes.MapRoute(
name: "Default",
url: "shop|articles/{action}/{id}",
defaults: new { controller = "Store", action = "Index", id = UrlParameter.Optional }
);

最佳答案

您可以使用路由约束,在其中指定由竖线分隔的有效值。

routes.MapRoute(
name: "Default",
url: "{page}/{action}/{id}",
defaults: new { controller = "Store", action = "Index", id = UrlParameter.Optional },
constraints: new { page = "shop|articles" });

关于c# - MVC URL 模式中的 OR 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22207263/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com