我有一个具有 ODataRoute 的 HttpGet 方法
["Users({userId}/Tags)"]
userId
是一个字符串,方法名是UserTags
。 Controller 是 UsersController
。
当我运行该应用程序时,出现以下错误:
The path template
Users({userId})/Tags
on the action 'UserTags' in controllerUsers
is not a valid OData path template. Found an unresolved path segmentTags
in the OData path templateUsers({userId})/Tags
.
最佳答案
ODataRoute
的约束非常严格,您的用户实体必须有一个名为“Tags”的集合属性才能使您的路由生效。
使用下面的代码,我让它正常工作:
public class UserController : ODataController
{
[HttpGet]
[System.Web.OData.Routing.ODataRoute("User({userId})/Tags")]
public IHttpActionResult GetTags([FromODataUri]int userId)
{
//...
}
}
public class User
{
[Key]
public int Id { get; set; }
public List<Tag> Tags { get; set; }
}
关于c# - OData 路径模板不是有效的 OData 路径模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49319111/