문제

I'm writing an MVC route and i was wondering, can i use something like an OR operator in it?

Something like this, where my Urls can either start with "shop/" or with "articles/"?

        routes.MapRoute(
            name: "Default",
            url: "shop|articles/{action}/{id}",
            defaults: new { controller = "Store", action = "Index", id = UrlParameter.Optional }
        );
도움이 되었습니까?

해결책

You could use a route constraint where you specify the valid values separated by pipes.

routes.MapRoute(
   name: "Default",
   url: "{page}/{action}/{id}",
   defaults: new { controller = "Store", action = "Index", id = UrlParameter.Optional },
   constraints: new { page = "shop|articles" });
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top