I have code like this that I repeat through many MVC editing views. This example is the default way we display a checkbox, but similar repetition is found with other input types.
<div class="form-group">
@Html.LabelFor(model => model.IsLive, htmlAttributes: new { @class = "control-label col-md-3" })
<div class="col-md-8 checkbox">
<div class="col-xs-1">
@Html.EditorFor(model => model.IsLive)
</div>
<div class="col-xs-10">
@Html.CheckboxLabelFor(model => model.IsLive)
</div>
</div>
<a class="infoonclick col-md-1" title="@Html.DisplayNameFor(model => model.IsLive)" data-content="@Html.DescriptionFor(model => model.IsLive)">
<span class="fa fa-info-circle"></span>
</a>
</div>
I am wondering what is the best way to DRY and standardise this?
I want to do something like @Html.DefaultCheckboxEditorFor(model => model.IsLive)
I tried creating a custom HtmlHelper, but this seemed to involve too many hard coded strings to be a good idea.
Rather I feel I should be using EditorTemplates for this, but I can't quite get the syntax right. The model for the view is a bool, but I need to get property specific stuff like the display name and descriptions.
@model bool
<div class="form-group">
@Html.LabelFor(model => model.IsLive, htmlAttributes: new { @class = "control-label col-md-3" })
<div class="col-md-8 checkbox">
<div class="col-xs-1">
@Html.EditorFor(model => model.IsLive)
</div>
<div class="col-xs-10">
@Html.CheckboxLabelFor(model => model.IsLive)
</div>
</div>
<a class="infoonclick col-md-1" title="@Html.DisplayNameFor(model => model.IsLive)" data-content="@Html.DescriptionFor(model => model.IsLive)">
<span class="fa fa-info-circle"></span>
</a>
</div>