Q:

error rgding definition & no extension method for System.Web.Routing.RouteValueDictionary

I am going through tutorial at 4GuysFromRolla website regarding Sorting and Paging a Grid of Data in ASP.NET MVC 2 by Scott Mitchell. I am receiving an error CS1061: 'System.Web.Routing.RouteValueDictionary' does not contain a definition for 'AddQueryStringParameters' and no extension method 'AddQueryStringParameters' accepting a first argument of type 'System.Web.Routing.RouteValueDictionary' could be found (are you missing a using directive or an assembly reference?). I am not sure if I need to add a dll reference or something else. Please could someone advise how to solve this thanks in advance. Also I downloaded the demo and there is no problem. error is in PagerLink.ascx file..routeData.AddQueryStringParameters(); // error pointing here
RouteValueDictionaryExtensions.cs looks like this (this is the helper file)...
using System.Web.Routing;
namespace Web
{
  public static class RouteValueDictionaryExtensions
  {
     public static RouteValueDictionary  
     AddQueryStringParameters(this RouteValueDictionary dict)
     {
       var querystring = HttpContext.Current.Request.QueryString;

        foreach (var key in querystring.AllKeys)
            if (!dict.ContainsKey(key))
                dict.Add(key, querystring.GetValues(key)[0]);

        return dict;
    }

    public static RouteValueDictionary ExceptFor(this RouteValueDictionary  
                dict, params string[] keysToRemove)
    {
        foreach (var key in keysToRemove)
            if (dict.ContainsKey(key))
                dict.Remove(key);

        return dict;
    }
}

}
Global.asax.cs looks like this...
enter code here
namespace GridDemosMVC
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode, 
// visit http://go.microsoft.com/?LinkId=9394801

public class MvcApplication : System.Web.HttpApplication
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = 
            UrlParameter.Optional } // Parameter defaults
   );

  }

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        RegisterRoutes(RouteTable.Routes);
    }
}
}

I am also using Dynamic.cs file which is available at microsoft to download.

A:

You need to add a using statement and <%@ Import directive for the namespace with the extension method.
Alternatively, you can move the extension method into your project's namespace.

