Click here to Skip to main content
15,888,968 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi all,

I am using the web grid with pagination in my MVC project.

also i maintaining the value in one hidden field,

the problem is while i click the next page link in web grid the hidden field values are lost, so help me to resolve this issue.

thanks in advance,
velsamy

What I have tried:

i have searched in google , didnt get anything
Posted
Updated 31-Aug-16 4:18am
Comments
Nathan Minier 31-Aug-16 8:14am    
What JS framework are you using? Also, we need to see some code in order to understand what's going on, specifically the Razor and ideally whatever you're using for pagination on the client side.

1 solution

The pager link makes a GET request. It does not pass across any other fields from your form.

To resolve this, you'll need to use Javascript to intercept the click event on the page links, and submit the form instead. This StackOverflow answer[^] describes how:
@Html.HiddenFor(x => x.Page, new { id = "page" })

JavaScript
$(function () {
    $('tfoot a').click(function () {
        // when the user clicks on any of the pager links
        // try to extract the page number from the link and
        // set the value of the hidden field
        var page = this.href.match(/page=([0-9])+/)[1];
        $('#page').val(page);

        // submit the form so that the POST action is invoked
        // passing along the search criteria (Name and Year) along
        // with the page hidden field value to the Index action
        $('form').submit();

        // cancel the default action of the link which is to simply redirect
        // to the Index action using a GET verb.
        return false;
    });
});
 
Share this answer
 
Comments
avelsamy 1-Sep-16 1:33am    
i have used this ...
but even the function not triggering...

$(function () {
$('#divid a').click(function () {
var page = this.href.match(/page=([0-9])+/)[1];
$('#page').val(page);


$('form').submit();
return false;
});
});

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900