asp.net mvc - How to retain data (form) on custom pagination using MVC? -
i have grid (list generated using scaffolding option) search criteria. , created paging concept. entered search criteria data , search, after post back, retained form data using tempdata. but, if click page numbers in grid, form data not retained , grid getting refreshed.
is there way retain data on pagination?
thanks!
i added hidden field dynamically within form using javascript. page number stored in hidden field, when user click page number, submit form. working without issue.
paging:
<button onclick="navigateto(this, '@url.routeurl("defined_route", new { currentpage = j })');">@j</button>
javascript:
$(function () { //page load - create hidden field, if search button found if ($("#search")) // button id { var element = document.createelement("input"); element.type = "hidden"; element.id = "currentpage"; element.name = "currentpage"; element.value = '@tempdata["page"]'; if (isnan(element.value)) element.value = "1"; $(to).parent().append(element); } }); function navigateto(field, url) { $("#currentpage").val(field.innertext); if (isnan($("#currentpage").val())) { location.href = url;//this direct url, ie. no search form } else { $("form").action = url; $("form").submit(); } }
Comments
Post a Comment