MVC 5 助手错误

MVC 5 Helper error

我有这个非常短的自定义助手

using System.Web.Mvc;

namespace Colibri.HtmlHelpers
{
    public static class CustomHelper
    {
        public static MvcHtmlString SearchBar(this HtmlHelper helper, string type)
        {
            return new MvcHtmlString("<input type=\"text\" placeholder =\"Recherche...\" id=\"" + type + "-Search\" class=\"Search-Input\"/>");
        }
    }
}

在 Razor Web.config 中,我在适当的部分添加了命名空间:

<add namespace="Colibri.HtmlHelpers" />

我只想使用以下代码从视图中调用它:

@Html.SearchBar("Article")

这里我得到这个错误:

Error CS0121 The call is ambiguous between the following methods or properties: 'Colibri.HtmlHelpers.CustomHelper.SearchBar(System.Web.Mvc.HtmlHelper, string)' and 'Colibri.HtmlHelpers.CustomHelper.SearchBar(System.Web.Mvc.HtmlHelper, string)'

如果我不在 Web.config 中添加命名空间,它会显示:

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

感谢您的帮助。

感谢大家的帮助。

我发现了问题:我刚刚将 .cs 文件从 App_Code 目录移动到另一个目录。

现在可以正常使用了。