MVC extension method error

asp.net-mvc-3c#-4.0extension-methods

Hi i've got an extension method in my PagingHelpers class:

 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());
        }
    }
}

here i call extension method in the List.cshtml:

@Html.PageLinks(Model.PagingInfo, x => Url.Action("List", new {page = x}))

And I got this error:

'System.Web.Mvc.HtmlHelper'
does not contain a definition for 'PageLinks' and no extension method
'PageLinks' accepting a first argument of type
'System.Web.Mvc.HtmlHelper'
could be found (are you missing a using directive or an assembly
reference?)

I added the namespace in the web.config inside the Views Folder:

<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>

Please help me, I don't know how could I solve this problem

Best Answer

Try adding

@using SportsStore.WebUI.HtmlHelpers;

to the top of your .cshtml file

your namespace approach should work as well, so try to shut down the server rebuild your solution and run again