Bootstrap被封裝的彈層,bootstrap封裝

來源:互聯網
上載者:User

Bootstrap被封裝的彈層,bootstrap封裝

對於Bootstrap的彈層,外掛程式有很多,今天主要用的是它內建的功能,通過bootstrap提供的強制回應視窗來實現的,而小編主要對使用方法進行了封裝,開發人員可以自己動態傳入彈層的HTML內容,可以控制按鈕的顯示與隱藏,使用者通過MVC擴充方法對彈層進行產生,然後使用A標籤進行調用.

具體使用很簡單

@Html.GenerateDialog("測試",true, @<div><form action="/home/index">hello world!</form></div>)<a data-toggle='modal' data-target='#LindModal'>測試彈層</a>

上面代碼分為兩塊,第一塊MVC擴充方法,主要用於在頁面上輸出彈層的程式碼片段,第二段是A標籤的調用,主要用於綁定上面的彈層控制項.

下面主要看一下彈層的擴充方法,它使用了Func<string, HelperResult>這個委託,用來接收前台的HTML程式碼片段,這對於開發人員是個福音,你不用關心如何去拼接HTML代碼了,而是直接把前台給我們的代碼複製過來即可.

彈層方法

#region Bootstrap彈層/// <summary>/// bootstrap風格的彈層/// </summary>/// <param name="htmlHelper"></param>/// <param name="isBtn"></param>/// <param name="result"></param>/// <returns></returns>public static MvcHtmlString GenerateDialog(this HtmlHelper htmlHelper, bool isBtn, Func<string, HelperResult> result){return GenerateDialog(htmlHelper, "詳細", isBtn, result);}/// <summary>/// bootstrap風格的彈層/// </summary>/// <param name="htmlHelper"></param>/// <param name="title"></param>/// <param name="isBtn"></param>/// <param name="result"></param>/// <returns></returns>public static MvcHtmlString GenerateDialog(this HtmlHelper htmlHelper, string title, bool isBtn, Func<string, HelperResult> result){string templete = @"<div class='modal fade' id='LindModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'><div class='modal-dialog'><div class='modal-content'><div class='modal-header'><button type='button' class='close'data-dismiss='modal' aria-hidden='true'>×</button><h4 class='modal-title' id='myModalLabel'>"+title+@"</h4></div><div class='modal-body' id='dialogContent'>" + result.Invoke(null) + "</div>";if (isBtn){templete +=@"<div class='modal-footer'><button type='button' class='btn btn-warning'data-dismiss='modal'>關閉</button><button type='button' class='btn btn-primary' id='subBtn'>提交</button></div>";}templete +=@"</div></div></div><script>$('#subBtn').click(function(){$('#dialogContent form').submit();});</script>";return MvcHtmlString.Create(templete);}#endregion

而啟動並執行效果是我們可以想到的

以上所述是小編給大家介紹的Bootstrap被封裝的彈層,希望對大家有所協助,如果大家有任何疑問請給我留言,小編會及時回複大家的。在此也非常感謝大家對幫客之家網站的支援!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.