Self-closing helpers are helpers that can contain HTML and Razor markup. The built-in @Html.BeginForm()
helper is an example of this type of helper.
In order to create this type of HTML helper, we'll need to create a helper class that implements the IDisposable
interface. Using the IDisposable
interface, we can write the element's closing tags when the object is disposed.
The Bootstrap Panel
component is a perfect candidate for such a helper. To create the helper, we'll have to complete the following steps:
Create a new subfolder called
Panels
inside theHelpers
folder in your project.Open the
Enums.cs
file, and add a new item calledPanelStyle
:public enum PanelStyle { Default, Primary, Success, Info, Warning, Danger }
Add a new class file called
Panel.cs
to thePanels
folder.Add a new private read-only field to the class called
_writer
.Create a constructor for the
Panel
class that accepts three parameters. The first is a reference to the...