OData路径模板不是有效的OData路径模板 [英] OData path template is not a valid OData path template

查看:180
本文介绍了OData路径模板不是有效的OData路径模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有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 controller Users is not a valid OData path template. Found an unresolved path segment Tags in the OData path template Users({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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆