26.06.2017 Views

Bootstrap for ASP.NET MVC

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The following code will create a button that will show a modal with the ID that<br />

was speciied as parameter to the TriggerModal method once it is clicked on.<br />

The Modal object is declared using the disposable Begin method in conjunction<br />

with the Modal class. The heading is created using the Header method and the<br />

body content is contained inside the BeginBody method.<br />

Chapter 9<br />

@Html.<strong>Bootstrap</strong>().Button().Text("Show Modal").TriggerModal("myModal")<br />

@using (var modal = Html.<strong>Bootstrap</strong>().Begin(new Modal().Id("myModal")))<br />

{<br />

@modal.Header("Modal Heading")<br />

using (modal.BeginBody())<br />

{<br />

Aliquam porttitor faucibus lectus, quis hendrerit<br />

orci scelerisque sit amet. Cras est augue.<br />

Aliquam imperdiet nibh eget libero rutrum sodales. <br />

}<br />

using (modal.BeginFooter())<br />

{<br />

@Html.<strong>Bootstrap</strong>().Button().Text("Close").Style<br />

(ButtonStyle.Info);<br />

}<br />

}<br />

The result should be a modal dialog with a blue info <strong>Bootstrap</strong> button as the modal<br />

close button, as shown in the following screenshot:<br />

[ 171 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!