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 controllerUsers
is not a valid OData path template. Found an unresolved path segmentTags
in the OData path templateUsers({userId})/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; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With