我正在将一个旧的第三方项目从MVC1迁移到MVC2,我对此并不十分熟悉。 MVC2中记录的重大变化之一是“对DefaultControllerFactory类的更改打破了从中派生的自定义控制器工厂”,如上所述here。我在项目代码中有多个位置,类似于下面的示例,它返回以下错误。
System.Web.Mvc.DefaultControllerFactory不包含定义 'RequestContext'并没有扩展方法'RequestContext' 接受第一个类型的参数 可以找到'System.Web.Mvc.DefaultControllerFactory'(是吗? 缺少using指令或程序集引用?)
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();
}
}
如何重写此代码以与MVC2兼容?谢谢。