In the documentation of ODATA's WebAPI there is a page about Attribute Routing.
In this page, there is an example about using ODataRoutePrefixAttribute when all requests to a particular controller have the same prefix, and this prefix can include a parameter. In the sample, all action methods declare the same parameter. From their sample:
[ODataRoutePrefix("Customers({id})")]
public class MyController : ODataController
{
[ODataRoute("Address")]
public IHttpActionResult GetAddress(int id)
{
......
}
[ODataRoute("Address/City")]
public IHttpActionResult GetCity(int id)
{
......
}
[ODataRoute("/Order")]
public IHttpActionResult GetOrder(int id)
{
......
}
}
I would like to avoid repeating the parameter in each and every method and just have it be a property of the class, like this:
[ODataRoutePrefix("Customers({id})")]
public class MyController : ODataController
{
public int Id
{
get { ... }
}
[ODataRoute("Address")]
public IHttpActionResult GetAddress()
{
......
}
}
How to get the value of the id
parameter from the URL when it is not passed as parameter to the action method?