c# - WebGrid pagination issue in MVC3 -


the issue pagination working fine till 9th page number , when request page in double or more digits takes last digits , ignore rest, say e.g. if request page number 10 displays page 0 passing "?page=0" query string , discards 1 , if request page number e.g. 458 shows page number 8 passing "?page=8" query string , discards 45 458. here code:

in javacsript:

        $(function () {     $('tfoot a').click(function () {         // try extract page number link         var page = this.href.match(/page=([0-9])+/)[1];          // submit form post action invoked         var form = document.forms[0];         form.action = '/session/index?page=' + page;         form.submit();          return false;     }); });       </script> 

in view:

    var grid = new webgrid(source: model.listsessions, rowsperpage: 5,     canpage: true, cansort: false, defaultsort: "absentee");       @grid.gethtml(     htmlattributes: new { id = "grid" },     tablestyle: "grid",     headerstyle: "head",     alternatingrowstyle: "alt",     columns: grid.columns(                             grid.column(format: @<text> <input type="hidden" id="colorcodevalue" name="colorcodevalue" value="@item.colorcodevalue" /> </text>, style: "width:0px;"),                             grid.column("createdby", "created by"),                             grid.column("session title", format: (item) => html.actionlink((string)item.sessiontitle, mvc.session.actionnames.editsession,                             new { id = item.sessionid })),                             grid.column("sessionid", "simple session id"),                             grid.column("startdate", "start date"),                             grid.column("starttime", "start time"),                                                            grid.column("sessionstatus", "status"),                             grid.column("prep materials", format: @<text><a  onclick="sessionclick();" id="@item.enableviewlink" href="@url.action(mvc.session.actions.viewsession((string)item.sessionid))">view</a><a id="uploadsessionmaterial"  href="@url.action(mvc.session.actions.uploadsession((int32)item.sessionid))">upload</a>  </text>),                             grid.column("action", format: @<text><a   href="@url.action(mvc.session.actions.viewsession((int)item.sessionid))">view</a><a id="@item.ispublished" class="@item.istranscriptexists" href="@url.action(mvc.session.actions.edittranscript((int32)item.sessionid))">edited session </a></text>)                                      ), mode: webgridpagermodes.all) 

and in controller:

    [httppost]     public virtual actionresult index(sessionviewmodel model)     {         model = getsessionlisting(model);         return view(model);     }       private sessionviewmodel getsessionlisting(sessionviewmodel model)     {         if (model == null)         {             model = new sessionviewmodel();         }         int page = 1;         if (convert.toint64( request["page"]) != null)             int.tryparse(request["page"], out page);          //rest of coding here                     return model;     } 

any great! if still need ask more please ask me. thanks!

// try extract page number link var page = this.href.match(/page=([0-9])+/)[1]; 

correct:

// try extract page number link var page = this.href.match(/page=([0-9]+)/)[1]; 

you need "+" inside "()" because "+" required on match pattern , not pattern group trying here.

regular expressions tricky!!


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -