OData路径模板不是有效的OData路径模板 [英] OData path template is not a valid OData path template
问题描述
我有一个具有ODataRoute的HttpGet方法
I have a HttpGet method that has the ODataRoute
["Users({userId}/Tags)"]
userId
是字符串,方法名称是UserTags
.控制器为UsersController
.
userId
is a string and the method name is UserTags
. Controller is UsersController
.
运行应用程序时,出现以下错误:
When I run the app I get the following error:
动作'UserTags'中的路径模板
Users({userId})/Tags
控制器Users
不是有效的OData路径模板.找到了 OData路径模板中的未解析路径段Tags
Users({userId})/Tags
.
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"的集合属性才能工作.
The constraints for ODataRoute
are pretty strict, your user entity must have a collection property called 'Tags' for your route to work.
使用以下代码,我可以正常运行:
With the following code I got it to work without errors:
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; }
}
这篇关于OData路径模板不是有效的OData路径模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!