我添加以下路由属性:
[HttpGet]
[Route("add")]
[Route(@"{id:int}/{inn:regex(^[0-9]+$)}/incBalance:range(0,1)/{dateSet:datetime}/{dateNext:datetime}")]
public IActionResult Add(int id, string inn, int incBalance, DateTime dateSet, DateTime dateNext)
{
....
}
在执行时发生错误:
An unhandled exception occurred while processing the request.
InvalidOperationException: The following errors occurred with attribute routing information:
Error 1:
For action: 'WebProject.Areas.DAS.Controllers.ReportController.Add'
Error: While processing template 'das/report/[action]/{id:int}/{inn:regex(^[0-9]+$)}/incBalance:range(0,1)/{dateSet:datetime}/{dateNext:datetime}', a replacement value for the token '0-9' could not be found. Available tokens: 'action, area, controller'.
我删除了regex(^[0-9]+$)
,一切正常
在中使用regex时,RouteAttribute
必须使用和转义[
和]
字符,因为和保留给控制器参数(动作,控制器和区域),如中。[[
]]
[
]
[Route("api/[controller]/[action]")]
更新:相同的适用于{
和}
您使用{{
和对其进行转义的地方}}
,但是这对您在中设置的默认路由也有效app.UseMvc( route => ... )
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句