我添加以下路由属性:
[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]+$)
一切正常
当您在中使用正则表达式时RouteAttribute
你必须逃脱[
and ]
字符与[[
and ]]
, 因为[
and ]
为控制器参数(动作、控制器和区域)保留,如[Route("api/[controller]/[action]")]
.
Update: 同样适用于{
and }
你在哪里逃避它{{
and }}
,但这对于您设置的默认路由也有效app.UseMvc( route => ... )
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)