tags:

views:

79

answers:

1

I'm trying to build a pager where it's just Next / Previous buttons that call a jquery function that post a JSON request. Inside the function, the current page "index" is retrieved from a hidden field and passed to the controller. Inside the controller, I reset the index if I'm on the last page of data. How would I pass the new index value back to the view? Or is there a better way to do what i'm trying to do?

Thanks

+1  A: 

Daniel Shaffer is right, you should not re-invent the wheel.

But if you really want to do it yourself: I assume you are using the jquery load() method or something similar to dynamically load the new list content and then insert the new code into the page.

In that case, if you want to reset your index counter, you can simply use a document ready handler:

<script type="text/javascript">
    $(document).ready(function() {
        yourCounter=<%=Model.NewCounterValue%>;
    })       
</script>

If this looks confusing, it's because <%=Model.NewCounterValue%> is a server-side tag embedded in a javascript block. You'll get used to it :-)

As soon as you insert this into your DOM, the document.ready handler is executed, just as it would be on a regular web page.

Adrian Grigore
Thanks guys for answering. The first solution would be great if it actually worked. There is little to no documention on how to use it, the demo page for the site no longer works, and demo page that comes in the zipped file just shows "Click the pager below". So now my options are A :( Waste time trying to figure out whats wrong with someone elses code or B :) Invent my own wheel which when broken, I'll know how to fix. Anywho, Adrian, I'll use your example as a starting point. Thanks.
To follow up, this site had the solution I was looking for:http://xlib.wordpress.com/2009/06/29/asp-net-mvc-grid-%E2%80%93-part-2-paging/But thanks again to everyone who tried to help me.