C# 无法在视图中使用我的HtmlHelper

C# 无法在视图中使用我的HtmlHelper,c#,asp.net-core,asp.net-core-mvc,C#,Asp.net Core,Asp.net Core Mvc,试图在新的asp.net vNext项目中使用我的mvc5项目,我无法使用自动格式化文本框的HtmlHelper 这是我的助手扩展类: namespace MyNamespace.Helpers { public static class YokoHelper { public static HtmlString YokoTextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHe

试图在新的asp.net vNext项目中使用我的mvc5项目,我无法使用自动格式化文本框的HtmlHelper

这是我的助手扩展类:

namespace MyNamespace.Helpers
{
    public static class YokoHelper
    {
        public static HtmlString YokoTextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper,
                                                                    Expression<Func<TModel, TProperty>> expression,
                                                                    string identifiant,
                                                                    string label)
    {
        string htmlString = string.Format("<span class=\"input\">" +
                                                "{0}" +
                                                "<label class=\"input-label label-yoko\" for=\"{1}\">" +
                                                    "<span class=\"label-content label-content-yoko\">{2}</span>" +
                                                "</label>" +
                                            "</span>",
                                            htmlHelper.TextBoxFor(expression, new { @class = "input-field input-yoko", @id = identifiant }),
                                            identifiant,
                                            label);

        return new HtmlString(htmlString);
    }
}
试着像这样使用我的助手:

@Html.YokoTextBoxFor(m => m.Email, "email", "Email")
知道我做错了什么吗?或者为什么它不能与vNext一起工作

提前谢谢


编辑:

似乎第一个参数必须是IHtmlHelper而不是HtmlHelper(MVC6VSMVC5)


修改后的代码在下面的回答中。

显然,在MVC6中,第一个参数必须是IHtmlHelper而不是HtmlHelper

以下是修改后的代码:

    public static HtmlString YokoTextBoxFor<TModel, TProperty>(this IHtmlHelper<TModel> htmlHelper,
                                                                    Expression<Func<TModel, TProperty>> expression,
                                                                    string identifiant,
                                                                    string label)
    {
        string htmlString = string.Format("<span class=\"input\">" +
                                                "{0}" +
                                                "<label class=\"input-label label-yoko\" for=\"{1}\">" +
                                                    "<span class=\"label-content label-content-yoko\">{2}</span>" +
                                                "</label>" +
                                            "</span>",
                                            htmlHelper.TextBoxFor(expression, new { @class = "input-field input-yoko", @id = identifiant }),
                                            identifiant,
                                            label);

        return new HtmlString(htmlString);
    }
public static HtmlString YokoTextBoxFor(此IHtmlHelper htmlHelper,
表情表情,
字符串标识符,
字符串标签)
{
字符串htmlString=string.Format(“”)+
"{0}" +
"" +
"{2}" +
"" +
"",
htmlHelper.TextBoxFor(表达式,新的{@class=“input field input yoko”,@id=identifiant}),
身份证明人,
标签);
返回新的HtmlString(HtmlString);
}

您的助手的命名空间是“MyNamespace.Helpers”。您在视图中使用的是“ouAllonSous.Helpers”命名空间。不,对不起,我为帖子重命名了我的命名空间。我回答了自己的问题,因为我找到了解决方案。谢谢@Rogerwillam的评论确保你接受自己的答案,@Béranger!
    public static HtmlString YokoTextBoxFor<TModel, TProperty>(this IHtmlHelper<TModel> htmlHelper,
                                                                    Expression<Func<TModel, TProperty>> expression,
                                                                    string identifiant,
                                                                    string label)
    {
        string htmlString = string.Format("<span class=\"input\">" +
                                                "{0}" +
                                                "<label class=\"input-label label-yoko\" for=\"{1}\">" +
                                                    "<span class=\"label-content label-content-yoko\">{2}</span>" +
                                                "</label>" +
                                            "</span>",
                                            htmlHelper.TextBoxFor(expression, new { @class = "input-field input-yoko", @id = identifiant }),
                                            identifiant,
                                            label);

        return new HtmlString(htmlString);
    }