MVC 知识点学习2

时间:2024-10-26 14:03:44

1、_Layout.cshtml   @RenderBody()

2、自定义扩展HtmlHelper(需要添加Bootstrap.js或者Bootstrap.min.js文件到项目中)

namespace System.Web.Mvc.Html //Mvc4Bootstrap.App_Start
{
  public static class ButtonHelper
  {
      //public static MvcHtmlString Button(string caption,string style,string size)
      //{
      // return new MvcHtmlString("<button type=\"button\" class=\"" + style + " btn-"+size+"\" >" + caption + "</button>");
      //}
       public static MvcHtmlString Button(this HtmlHelper helper,string caption, string style, string size)
       {
              return new MvcHtmlString("<button type=\"button\" class=\"" + style + " btn-" + size + "\" >" + caption + "</button>");
       }
   }
}

调用时@Html.Button("按钮","stylename","sizename")

3、MVC+Bootstrap下拉框

MVC  知识点学习2

<div class="form-group">
@*Bootstrap下拉框*@
<div class="col-md-10">
<div id="territorydropdown" class="dropdown">
<button id="territorybutton" class="btn btn-sm btn-info" data-toggle="dropdown">显示方式</button>
<ul id="territories" class="dropdown-menu">
@*@foreach (var item in ViewBag.TerritoryId)
{*@
<li><a href="#" tabindex="-1" data-value="value">单选</a></li>
<li><a href="#" tabindex="-1" data-value="value">多选</a></li>
@*}*@
</ul>
</div>
</div>
</div>