MVC扩展方法错误 [英] MVC extension method error

查看:270
本文介绍了MVC扩展方法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我已经得到了扩展方法在我PagingHelpers类:

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

在这里,我调用扩展方法在List.cshtml:

here i call extension method in the List.cshtml:

@ Html.PageLinks(Model.PagingInfo,X =&GT; Url.Action(列表,新的{页= X}))

和我得到这个错误:

System.Web.Mvc.HtmlHelper
  不包含定义关于'PageLinks'和没有扩展方法
  PageLinks接受式的第一个参数
  System.Web.Mvc.HtmlHelper
  可以找到(是否缺少using指令或程序集
  引用?)

'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?)

我添加了命名空间中的视图文件夹内的web.config中:

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

推荐答案

尝试添加

@using SportsStore.WebUI.HtmlHelpers;

您.cshtml文件的顶部

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

这篇关于MVC扩展方法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆