In WebForms, I could create a component where I could embed my own content
Example
<uc:BootstrapModal Title="Hello World" Size="Large">
<h1>Hello World</h1>
</uc:BootstrapModal>
<!--generates this...-->
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<h1>Hello World</h1>
</div>
</div>
</div>
How can I do this in MVC?
You can create a
HtmlHelper
extension method to generate the enclosing html, similar to the wayBeginForm()
generates enclosing<form></form>
tags.and in the view use it as
Note: In the
web.config
file add the namespace of your assembly so that you do not have to include@using
statements in the view.And you can then extend this by creating additional overloads, for example you might also have parameters for
string title
and aButtonType buttons
(an enum) to render a title bar and footer buttons in the dialog