有没有@ Html.Button! [英] There's no @Html.Button !

查看:191
本文介绍了有没有@ Html.Button!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是不可思议。我请参阅参考资料那里为@ Html.Button(),但是当我键入智能感知没有找到这样一个帮手...有DropDownList的,隐藏的,编辑,等等,但没有按钮!

什么回事?

解决方案

 公共静态类HtmlButtonExtension
{

  公共静态MvcHtmlString按钮(这HtmlHelper的帮手,
                                     字符串的innerHTML,
                                     对象htmlAttributes)
  {
    返回按钮(辅助,innerHTML的,
                  HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)
    );
  }

  公共静态MvcHtmlString按钮(这HtmlHelper的帮手,
                                     字符串的innerHTML,
                                     IDictionary的<字符串,对象> htmlAttributes)
  {
      VAR建设者=新TagBuilder(按钮);
      builder.InnerHtml = innerHTML的;
      builder.MergeAttributes(htmlAttributes);
      返回MvcHtmlString.Create(builder.ToString());
  }
}
 

this is weird. I see references out there for @Html.Button() but when I type that Intellisense doesn't find such a helper... there's dropdownlist, hidden, editors, et cetera, but no button!

what's up with that?

解决方案

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

这篇关于有没有@ Html.Button!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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