我正在通过4GuysFromRolla网站上的教程,了解斯科特·米切尔在ASP.NET MVC2中对数据网格进行排序和分页。我收到一个错误CS1061:'System.Web.Routing.RouteValueDictionary‘不包含'AddQueryStringParameters’的定义,并且找不到接受类型为'System.Web.Routing.RouteValueDictionary‘的第一个参数的扩展方法'AddQueryStringParameters’(是否缺少using指令或程序集引用?)。我不确定是否需要添加dll引用或其他内容。请提前告诉我如何解决这个问题,谢谢。我也下载了演示,没有任何问题。错误在PagerLink.ascx file..routeData.AddQueryStringParameters()中;//指向此处时出错
RouteValueDictionaryExtensions.cs看起来像这样(这是帮助文件)...
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看起来像这样...
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);
}
}
}我也在使用微软提供的Dynamic.cs文件进行下载。
发布于 2011-01-29 03:06:01
您需要使用扩展方法为命名空间添加一条using语句和<%@ Import指令。
或者,您可以将扩展方法移动到项目的命名空间中。
发布于 2011-02-13 06:57:17
在导入文件<%@ PagerLink.ascx Namespace="your project name space“%>中添加
发布于 2011-02-25 18:14:49
在2个用户控件(PagerLink.ascx和SmartLink.ascx)中引用命名空间web,如下所示。
<%@ Import Namespace="Web"%>
如果更改了现有命名空间,请使用项目的相应命名空间。
https://stackoverflow.com/questions/4831986
复制相似问题