I am looking to create an editor template for Object.cshtml to change the behavior of the Html.EditorForModel() method. I can\'t find any example of this using Razor. I have see
This seem to work for Editor Template for bootstrap, please let me know of any improvements
Object.cshtml
@if (Model == null)
{
@ViewData.ModelMetadata.NullDisplayText
}
else if (ViewData.TemplateInfo.TemplateDepth > 1)
{
@ViewData.ModelMetadata.SimpleDisplayText
}
else
{
foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForDisplay && !ViewData.TemplateInfo.Visited(pm)))
{
if (prop.HideSurroundingHtml)
{
@Html.Editor(prop.PropertyName)
}
else
{
@Html.Label(prop.PropertyName, new { @class = "control-label col-md-2", @style = "text-align:right;" })
@Html.Editor(prop.PropertyName, null, new { @class = "form-control " })
@Html.ValidationMessage(prop.PropertyName, "", new { @class = "text-danger" })
}
}
}