domingo, 31 de enero de 2010

Ajax Paging with ASP.NET MVC

Etiquetas de Technorati: ,,,,

First of all, I want to give thanks to Martijn Boland for the MVC Paging Solution (wich was the base for my addition).

Why to give thanks? Because it was really easy to understand and also to add functionality to it!!!! Awesome!!!!

Before going on, I strongly recomend you to visit his paging post first to have an initial aproach about the MVC Paging. I’m going to explain the AJAX added features only in this post.

(Download sources)

image

You will find I have added two clases to the original MvcPaging solution.

- AjaxPagingExtensions.cs
- AjaxPager.cs

This two files were all the necesary additions to made the Ajax paging possible.

The AjaxPagingExtensions class:
Inside the AjaxPagingExtensions.cs file you will find all the overloaded extension methods for the AjaxHelper type. This methods are pretty much the same than the ones on PagingExtensions.cs (I did a quick copy and paste indeed :-)) but this new ones take an AjaxOptions as second parameter.

The AjaxPager class:
Once again, you will find that it is almost the same than the content of the Pager.cs file (copy and paste strykes again!!). The only changes I had to made were:

1- Change the constructor in order to receive some additional parameters (like AjaxOptions) and the AjaxHelper itself.

2- Change the GeneratePageLink method, where I only had to pass the responsability of making the link to the AjaxHelper.ActionLink method.

And… that is all about the MvcPaging library… but not all about making AjaxPaging possible.

You will find inside the Demo solution how to add ajax paging to your code. And, you can see my new post explaining how to add paging to your Mvc application.

I hope you will find it usefull!!!

(Download sources)

2 comentarios:

  1. Hi Daniel, thanks in advance for your Ajax paging solution. May I ask you a question, taking into consideration ProductsByCategory.aspx with categoryname = ViewData [categorydisplayname] , what do I have to change in order to use the proposed solution but using categoryid (an int instead of current string) retrieved from a database eg db.Category
    thank you so much for your help, s

    ResponderEliminar
  2. Hi Daniel, i m facing some problem, when i m using in mvc 3. @Ajax.Pager giving the error & i m using nlayer architecture. so how to use in MVC 3 with stored procedure. please help me.

    ResponderEliminar