//文章
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.
{cid}-{pageindex?} 可以换成正则表达式. 或者实现一个IRouteConstraint, 规则想怎么写就怎么写.
换成正则表达式怎么弄呢?