我的ASP.NET Core的默认路由与VS2015默认设置相同:
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
当我请求URL /my-controller/my-special-view时,它确实调用了我在my-control中定义的方法,该方法如下所示,其中id参数等于my-special-value。
public IActionResult my-controller(string id) {...
我正在尝试使用属性路由实现相同的功能。我定义属性如下:
[Route("my-controller/{id}")]
public IActionResult my-controller(string id) {...
我收到以下错误信息:
InvalidOperationException: The constraint entry 'attributeOfInterest' - 'string' on the route 'CacheTagHelper/{attributeOfInterest:string}' could not be resolved by the constraint resolver of type 'DefaultInlineConstraintResolver'.
我没有经验使用属性路由,不明白为什么上述两个控制器方法不能给我相同的结果。