【发布时间】:2011-12-26 21:26:32
【问题描述】:
您好,我的 PagingHelpers 类中有一个扩展方法:
namespace SportsStore.WebUI.HtmlHelpers
{
public static class PagingHelpers
{
public static MvcHtmlString PageLinks(this HtmlHelper html,
PagingInfo pagingInfo,
Func<int, string> pageUrl)
{
StringBuilder result = new StringBuilder();
for (int i = 1; i < pagingInfo.TotalPages; i++)
{
TagBuilder tag = new TagBuilder("a");
tag.MergeAttribute("href", pageUrl(i));
tag.InnerHtml = i.ToString();
if (i == pagingInfo.CurrentPage)
tag.AddCssClass("selected");
result.Append(tag.ToString());
}
return MvcHtmlString.Create(result.ToString());
}
}
}
这里我调用 List.cshtml 中的扩展方法:
@Html.PageLinks(Model.PagingInfo, x => Url.Action("List", new {page = x}))
我得到了这个错误:
'System.Web.Mvc.HtmlHelper' 不包含“PageLinks”的定义和扩展方法 'PageLinks' 接受类型的第一个参数 'System.Web.Mvc.HtmlHelper' 可以找到(您是否缺少 using 指令或程序集 参考?)
我在 Views 文件夹内的 web.config 中添加了命名空间:
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages"/>
<add namespace="SportsStore.WebUI.HtmlHelpers"/>**
</namespaces>
</pages>
请帮帮我,我不知道我该如何解决这个问题
【问题讨论】:
标签: asp.net-mvc-3 c#-4.0 extension-methods