c# - WebApi Pagination not working, page is always 0 even when I set url parameter correctly -


the api controller method this:

        public ihttpactionresult gettblempleados(int page, int pagesize)         {             var query = db.spempleadosintranet().tolist();              var totalcount = query.count();             var totalpages = (int)math.ceiling((double)totalcount / pagesize);              var urlhelper = new urlhelper(request);             var prevlink = page > 0 ? urlhelper.link("empleados", new { page = page - 1, pagesize = pagesize }) : "";             var nextlink = page < totalpages - 1 ? urlhelper.link("empleados", new { page = page + 1, pagesize = pagesize }) : "";              var results = query             .skip(pagesize * page)             .take(pagesize)             .tolist();              return ok(query);         } 

and url use consume service is:

however, page 0, prevlink empty http://localhost:12929/api/empleados?page=0&pagesize=10

the error this: (sorry framework in spanish)

translatio says cant find path /empleados

no se encuentra ninguna ruta con el nombre 'empleados' en la colección de rutas.\r\nnombre del parámetro: name"

this controller

public class empleadoscontroller : apicontroller { 

and globa.asax

protected void application_start() {     globalconfiguration.configuration.formatters.clear();     globalconfiguration.configuration.formatters.add(new jsonmediatypeformatter());     arearegistration.registerallareas();     globalconfiguration.configure(webapiconfig.register);     filterconfig.registerglobalfilters(globalfilters.filters);     routeconfig.registerroutes(routetable.routes); 

update1

this webapiconfig

public static void register(httpconfiguration config)          {              // web api configuration , services              // web api routes              config.maphttpattributeroutes();              config.routes.maphttproute(                  name: "defaultapi",                  routetemplate: "api/{controller}/{id}",                  defaults: new { id = routeparameter.optional }              );          } 

since using config.maphttpattributeroutes(); can use route prefixes follows , because using urlhelper.link method need set route name

[routeprefix("api/empleados")]    public class empleadoscontroller : apicontroller {      [route("", name="empleados")]     [httpget]     public ihttpactionresult gettblempleados(int page, int pagesize) {         var query = db.spempleadosintranet().tolist();          var totalcount = query.count();         var totalpages = (int)math.ceiling((double)totalcount / pagesize);          var urlhelper = new urlhelper(request);         var prevlink = page > 0 ? urlhelper.link("empleados", new { page = page - 1, pagesize = pagesize }) : "";         var nextlink = page < totalpages - 1 ? urlhelper.link("empleados", new { page = page + 1, pagesize = pagesize }) : "";          var results = query         .skip(pagesize * page)         .take(pagesize)         .tolist();          return ok(query);     } } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -