c# - Webgrid paging through generic controller method. -


i have generic method data grids in application, method gets data api , returns predefined grid populated said data. problem paging won't work - i.e. nothing happens - when have used method.

i thought might down url paging link calling - i.e. generic method - without knowing other data needs sent.

how can webgrid's pagination work generic method?

generic method

    /// <summary>generic grid request method. used render grid data defined location.</summary>     /// <param name="obj">the data required complete operation.</param>     /// <param name="obj[dataurl]">the url used data grid.</param>     /// <param name="obj[data]">any data needs sent data source when getting data grid.</param>     /// <param name="obj[gridurl]">the url grid rendered.</param>     /// <returns>the grid populated data in html format.</returns>     [handleerror]     [httppost]     public actionresult gridrequest(string obj)     {                     jobject request;         string dataurl, gridurl, requestdata;         try         {             request = jobject.parse(obj);             dataurl = (string)request["dataurl"];             requestdata = request["data"] != null ? request["data"].tostring() : null;             gridurl = (string)request["gridurl"];              httpclient client = new httpclient();             client.request.forcebasicauth = true;             client.request.setbasicauthentication(c4smvcapp.properties.settings.default.apiusername, c4smvcapp.properties.settings.default.apipassword);             httpresponse response = client.post(dataurl, requestdata, httpcontenttypes.applicationjson);             string result = response.rawtext;              if (response.statuscode != httpstatuscode.ok)             {                 throw new exception("grid request error" + result);             }             else             {                 jarray data = jarray.parse(result);                 return partialview(gridurl, data);             }         }         catch (exception)         {                             throw;         }     } 

ajax call

            $.ajax({                 type: "post",                 url: "/c4s/home/gridrequest",                 data: {                     obj: json.stringify({                         dataurl: "{0}community/aanewsapi/addtolist".format(apibaseurl),                         data: new object({ listid: listid, items: selectedresult }),                         gridurl: "~/areas/comms/views/home/grids/listpeoplegrid.cshtml"                     })                 }             }).done(function (data) {                 $('#persongrid').replacewith(data);                 $('#addusercontainer').addclass('hidden');                 listgrid();             }).fail(failcallback); 

webgrid

@model ienumerable<object> @{     webgrid listpeoplegrid = new webgrid(     source: model,     ajaxupdatecontainerid: "persongrid",     canpage: true,     rowsperpage: 16); } <div id="persongrid"> @listpeoplegrid.gethtml(     tablestyle: "webgrid",     headerstyle: "webgrid-header color-2",     footerstyle: "webgrid-footer color-2",     rowstyle: "webgrid-row",     alternatingrowstyle: "webgrid-row",     fillemptyrows: true,     nexttext: "next >",     previoustext: "< prev",     columns: listpeoplegrid.columns(     listpeoplegrid.column("id", style: "hidden"),     listpeoplegrid.column("name"),     listpeoplegrid.column("manager"),     listpeoplegrid.column("accesslevel"),     listpeoplegrid.column("site"),     listpeoplegrid.column("department") )) </div> 

i found answer here: webgrid pagination loose parameters post data

i needed catch event , append ?page=[pageno] url , include post data in data: property of ajax call.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -