My "unenhanced" code looks like this:
@using (Html.BeginForm("Index", "home"))
{
<!-- old group -->
<div class="form-group">
@Html.LabelFor(m => m.Query.artist)
@Html.TextBoxFor(m => m.Query.artist, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Query.artist)
</div>
...
}
But I want to enhance it and add a toggle feature for each form-group
, like this:
<script>
var toggleProperty = function(targetCheckbox) {
var id = targetCheckbox.id.split('-')[0];
var inputDiv = document.getElementById(id + "-inputdiv");
inputDiv.style.display = (inputDiv.style.display !== "none") ? "none" : "";
}
</script>
<!-- new group -->
<input type="checkbox" id="property1-toggler" value="false" onchange="return toggleProperty(this)"/> <label for="property1">name for property1</label>
<div id="property1-inputdiv">
<input class="form-control" id="property1" name="property1" type="text" value="property1 default value">
<span class="field-validation-valid" data-valmsg-for="property1" data-valmsg-replace="true"></span>
</div>
I would like to know where in the aspnet mvc source code I can find the code for LabelFor
etc.
This way I could better understand how it works, and create an extension function like:
public static IHtmlContent FullGroupFor<TModel, TResult>(this IHtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TResult>> expression);