开发者

mvc route problem - using integer parameters

开发者 https://www.devze.com 2022-12-17 11:01 出处:网络
I have a route like this in my global.asax.cs: routes.MapRoute( \"NewsArticles\", \"News/{page}\", new { controller = \"News\", action = \"Index\", archive = false }

I have a route like this in my global.asax.cs:

        routes.MapRoute(
           "NewsArticles",
           "News/{page}",
           new { controller = "News", action = "Index", archive = false }
       );

How can I restrict access to this route so that it's only encountered if the user uses an integer开发者_JS百科?


Make sure you put this route before the default route. You could also use regular expressions to restrict possible parameter values:

routes.MapRoute(
    "NewsArticles",
    "News/{page}",
    new { controller = "News", action = "Index" },
    new { page = @"^\d{1,3}$" }
);

Remark: In your example you are using archive = false while there is no archive parameter defined in the route.

0

精彩评论

暂无评论...
验证码 换一张
取 消