I am migrating an old 3rd party project from MVC1 to MVC2, which I am not very familiar with. One of the documented breaking change in MVC2 is "Changes to the DefaultControllerFactory class break custom controller factories that derive from it" as mentioned here. I have multiple locations in project code similar to below sample which returns following error.
System.Web.Mvc.DefaultControllerFactory does not contain a definition for 'RequestContext' and no extension method 'RequestContext' accepting a first argument of type 'System.Web.Mvc.DefaultControllerFactory' could be found (are you missing a using directive or an assembly reference?)
public static class DataUtil
{
private static readonly DefaultControllerFactory Factory =
ControllerBuilder.Current.GetControllerFactory() as DefaultControllerFactory;
private static void SetGridCookies(string orderByProperty, string sortDirection, int page, int pageSize)
{
if (HttpContext.Current.Response.Cookies["GridCookie"] == null)
{
HttpContext.Current.Response.Cookies.Add(new HttpCookie("GridCookie"));
HttpContext.Current.Response.Cookies["GridCookie"].Expires.AddMinutes(1);
}
HttpContext.Current.Response.Cookies["GridCookie"]["PageSize"] = pageSize.ToString();
HttpContext.Current.Response.Cookies["GridCookie"][string.Format("{0}_SortColumnName", Factory.RequestContext.RouteData.Values["pageName"])] = orderByProperty;
HttpContext.Current.Response.Cookies["GridCookie"]["SortDirection"] = sortDirection;
HttpContext.Current.Response.Cookies["GridCookie"][string.Format("{0}_CurrentPage", Factory.RequestContext.RouteData.Values["pageName"])] = page.ToString();
}
}
How can this code rewritten to be compatible with MVC2? Thank you.