Search code examples
asp.net-mvcrestasp.net-web-apiroutesodata

odata and webapi together in the same controller


I have the ticketController

public class ticketsController : ODataController
{
}

Is it possible to have this:

GET     /api/tickets?$skip={record_to_skip}&$top={pageSize}
GET     /api/tickets/{id}
PUT     /api/tickets/{id}
DELETE  /api/request/{id} 

First GET method uses odata routing, the second GET, PUT, and POST uses web api routing

Thanks


Solution

  • Yes it is possible but you have to use an OData attribute. Your controller should inherit from ApiController not ODataController and on the method/action you want to query paint it with the OData 'Queryable' attribute, check this out for more details:

    https://ovaismehboob.wordpress.com/2014/01/18/adding-queryable-support-to-asp-net-web-api-controller-action-methods/

    Also if you search for OData queryable attribute you should get a a load of information back