c# - Passing querystring parameters without using OData conventions? -
is there way pass querystring parameters asp.net mvc4 web api controller without using odata conventions outlined here?
http://www.asp.net/web-api/overview/web-api-routing-and-actions/paging-and-querying
i have repository methods built using dapper don't support iqueryable , want able manually paginate them without using odata conventions, whenever try doing traditional asp.net way "route not found" errors.
for instance, here's route:
context.routes.maphttproute( name: "apiv1_api_pagination", routetemplate: "api/v1/{controller}/{id}", defaults: new { area = areaname, controller = "category", offset = 0, count = 100}); and here's signature match
public class categorycontroller : apicontroller { // /api/<controller> public httpresponsemessage get(int id, int offset = 0, int count = 0) and whenever pass following query:
http://localhost/api/v1/category/1?offset=10
i following error:
no action found on controller 'category' matches request.
any suggestions on how work querystrings sanely in asp.net mvc4 web api?
when start use querystring call exact method of controller parameters. prefer change router :
context.routes.maphttproute( name: "apiv1_api_pagination", routetemplate: "api/v1/{controller}/{action}/{id}", defaults: new { area = areaname, controller = "category", offset = 0, count = 100}); and change method into
public httpresponsemessage items(int id, int offset = 0, int count = 0); from on whenever query
http://localhost/api/v1/category/items?id=1&offset=10&count=0 it run.
another method came mind while writing this. don't know if works try change router like
context.routes.maphttproute( name: "apiv1_api_pagination", routetemplate: "api/v1/{controller}/{id}/{offset}/{count}", defaults: new { area = areaname, controller = "category", offset = routeparameter.optional, count = routeparameter.optional});
Comments
Post a Comment