如何在 ASP.NET MVC Core 中进行多个路由约束?

tha*_*ung 3 c# asp.net-core-mvc asp.net-core asp.net-core-routing

我在互联网上搜索了很多,以找出如何进行约束,The Customer Id should be a guid and required以便我最终可以得到[HttpGet("{customerId:guid|required}")],但不幸的是没有任何解决方案可以这样做。来自 Microsoft 的文档https://learn.microsoft.com/en-us/aspnet/core/fundamentals/routing的“路由约束参考”部分也没有阐明这一点。任何人都可以像我刚才描述的那样执行多个约束值吗?先感谢您。

小智 5

只需用冒号分隔约束{customerId:guid:required}...。采用参数的约束也很容易以这种方式使用......{id:int:range(100, 999)}