首页 新闻 会员 周边

.net Core 路由规则

0
悬赏园豆:10 [待解决问题]
//文章
endpoints.MapControllerRoute(
   name: "Article",
   pattern:  "p/{id}",
   defaults: new { controller = "Article", action = "Index" });
//分类
endpoints.MapControllerRoute(
   name: "Category",
   pattern: "category/{cid}-{pageindex?}",
   defaults: new { controller = "Category", action = "Index"});

文章是可以匹配到,但是分类就报错了,不能用-吗?我用/是没问题的,但是用-就不行。

报错信息
RoutePatternException: In the segment '{cid}-{pageindex?}', the optional parameter 'pageindex' is preceded by an invalid segment '-'. Only a period (.) can precede an optional parameter.

低调De程序猿的主页 低调De程序猿 | 初学一级 | 园豆:38
提问于:2021-04-05 14:47
< >
分享
所有回答(1)
0

{cid}-{pageindex?} 可以换成正则表达式. 或者实现一个IRouteConstraint, 规则想怎么写就怎么写.

czd890 | 园豆:14412 (专家六级) | 2021-04-06 10:52

换成正则表达式怎么弄呢?

支持(0) 反对(0) 低调De程序猿 | 园豆:38 (初学一级) | 2021-04-06 12:26
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册