简体   繁体   中英

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

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 aa load of information back

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM