1. ホーム
  2. .net

[解決済み] Html.Buttonがない!?

2023-07-20 14:45:36

質問

これは奇妙です。 私は@Html.Button()のためのそこに参照を見るが、私がそれを入力するときIntellisenseはそのようなヘルパーを見つけない...ドロップダウンリスト、隠し、エディタ、その他はあるが、ボタンはない!

どうしたんですか?

どのように解決するのですか?

public static class HtmlButtonExtension 
{

  public static MvcHtmlString Button(this HtmlHelper helper, 
                                     string innerHtml, 
                                     object htmlAttributes) 
  { 
    return Button(helper, innerHtml,
                  HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)
    ); 
  }

  public static MvcHtmlString Button(this HtmlHelper helper, 
                                     string innerHtml,
                                     IDictionary<string, object> htmlAttributes)
  {
      var builder = new TagBuilder("button");
      builder.InnerHtml = innerHtml;
      builder.MergeAttributes(htmlAttributes);
      return MvcHtmlString.Create(builder.ToString());
  }
}