Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OData path template is not a valid OData path template

I have a HttpGet method that has the ODataRoute

["Users({userId}/Tags)"]

userId is a string and the method name is UserTags. Controller is UsersController.

When I run the app I get the following error:

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.

like image 773
OjamaYellow Avatar asked Mar 16 '18 10:03

OjamaYellow


1 Answers

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; }
}
like image 155
GWigWam Avatar answered Sep 18 '22 14:09

GWigWam