asp.net mvc 4 - Custom paging logic in MVC 4 view with Stored procedures -
i returning records stored procedure , want use custom paging in view. have far:
controller:
public actionresult index(int currentpage=1, int pageno = 1, int pagesize = 10, string sortcolumn = "name", string sortorder = "asc", string searchstring = "", int totalrecords=0) { datacontextdatacontext obj = new datacontextdatacontext(); system.nullable<int> total = null; //pagecount = (int)math.ceiling((double)total / pagesize); var model = obj.tempitemsubclasslist(pageno, pagesize, sortcolumn, sortorder, searchstring, ref total).tolist(); int pagecount = (int)(total + pagesize - 1) / pagesize; stringbuilder sb1 = new stringbuilder(); int seed = currentpage % pagesize == 0 ? currentpage : currentpage - (currentpage % pagesize); if (currentpage > 0) sb1.appendline(string.format("<a href=\"{0}/{1}\">previous</a>", searchstring, currentpage)); if (currentpage - pagesize >= 0) sb1.appendline(string.format("<a href=\"{0}/{1}\">...</a>", searchstring, (currentpage - pagesize) + 1)); (int = seed; < math.round((totalrecords / 10) + 0.5) && < seed + pagesize; i++) { sb1.appendline(string.format("<a href=\"{0}/{1}\">{1}</a>", searchstring, + 1)); } if (currentpage + pagesize <= (math.round((totalrecords / 10) + 0.5) - 1)) sb1.appendline(string.format("<a href=\"{0}/{1}\">...</a>", searchstring, (currentpage + pagesize) + 1)); if (currentpage < (math.round((totalrecords / 10) + 0.5) - 1)) sb1.appendline(string.format("<a href=\"{0}/{1}\">next</a>", searchstring, currentpage + 2)); //response.write(sb1);////can/should append model? return view(model); }
view:
@model ienumerable<artguildmvc2.models.tempitemsubclasslistresult> @{ viewbag.title = "index"; } <h2>index</h2> <p> @html.actionlink("create new", "create") </p> <table> <tr> <th> @html.displaynamefor(model => model.itemclassid) </th> <th> @html.displaynamefor(model => model.description) </th> <th></th> </tr> @foreach (var item in model) { <tr> <td> @html.displayfor(modelitem => item.itemclassid) </td> <td> @html.displayfor(modelitem => item.description) </td> <td> @html.actionlink("edit", "edit", new { id=item.id }) | @html.actionlink("details", "details", new { id=item.id }) | @html.actionlink("delete", "delete", new { id=item.id }) </td> </tr> } </table> /////what do hereafter???? @{ if (viewbag.currentpage > 1) { <a href="@url.action("index",new {page=1})">first</a> <a href="@url.action("index",new {page=viewbag.currentpage-1})">prev</a> } if (viewbag.currentpage < viewbag.total) { <a href="@url.action("index",new {page=viewbag.currentpage+1})">next</a> <a href="@url.action("index",new {page=viewbag.total})">last</a> }}
how implement paging logic in view? in advance. p.s.: may not find code logical since have picked 2-3 places , trying make work on trial & error basis.
i going break mvc pattern code have written in action method.
by way, paging solved problem libraries mvcpaging so, recommend using 1 of them.
Comments
Post a Comment