Updating MvcPager to work with ASP.NET MVC RC 1 (refresh)

Sunday, February 1, 2009

At first glance, upgrading to the RC1 was quite a debacle. First of all, any link that I created using the much more performant Html.RouteLink (instead of Html.ActionLink) just stopped working. It turns out there was a regression bug in the RC that caused this. The ASP.NET MVC team quickly released a refresh which fixed the problem.

The next problem came when I noticed Stephen Walther’s paging helper stopped working. It would throw a null reference exception whenever I used the Html.Pager() helper method. The issue was a breaking change in the RC1 with the location the RequestContext.

To fix the issue, you can download the solution from Stephen’s site. Open up the solution and change all the references to the latest ASP.NET MVC assemblies. When you compile the main project, you’ll find an error in the PagerBuilder.cs class at line 165. All you have to do is update this line to:

var urlHelper = new UrlHelper(_helper.ViewContext.RequestContext);

Compile the project and replace the assembly in your ASP.NET MVC project. I’m sure Stephen will update the project eventually so you could just download the latest version.

Hope this helps!


  1. http:// says:

    I have been noticing an error with MVC RC. The MVC beta on accessing dbnull values wasnt throwing any exception. this is excellent because bindingsource on windows forms works likewise…i dont want to force values to the database when such fields should contain DBNULL. How do i solve this issue with the MVC Release candidate

  2. http:// says:

    Hi, I looked at this example and it seems that the Model needs to be queried on each page. Is this so? Is there a way to preserve the state of model between controller calls?

    The scenario could be one in which the user retrives a large set of data (with many fields). Using a datagrid is not a practical way, so he has to browse each record.

    Thanks in advance!

  3. Mike Bosch says:

    That is correct, it will query on each page. The nice thing about MVC is that it doesn’t rely on state. You could probably use Session. Depending on your ORM layer, it might be more efficient to have the paging occur on the database layer.

Leave a Reply