Whenever I use @Html.EditorForModel()
following the standard template is displayed in asp.net mvc
Default in Asp.net MVC template
<div class="editor-label">
<label for="[MY-PROPERTY]">MY-PROPERTYNAME</label>
</div>
<div class="editor-field">
<input id="[MY-PROPERTYID]" name="MY-PROPERTYNAME" type="text" value="">
<span class="field-validation-valid" data-valmsg-for="MY-PROPERTYNAME" data-valmsg-replace="true"></span>
</div>
I would like to customize the format of this HTML!!
@Html.EditorForModel("MY-TEMPLATE")
@Html.EditorFor(p => p.MY-PROPERTY, "MY-TEMPLATE")
Views\{CONTROLLER}\EditorTemplates\{CLASSNAME\TYPE}
Views\Shared\EditorTemplates\{CLASSNAME\TYPE}
Without having to travel the entire project for this!
@Html.EditorForModel()
, each property will generate a HTML customized!!The new template would be something like this:
<div class="control-group">
@Html.LabelFor(p => p.PROPERTY, new { @class = "control-label" })
<div class="controls">
@Html.EditorFor(p => p.PROPERTY)
<span class="help-inline"></span>
</div>
</div>
You could create Object.cshtml
template to your Views\Shared\EditorTemplates\
folder and @Html.EditorForModel()
will use that template if it cannot find more specific one (for example template named classname.cshtml
)
You could further read Custom Object Templates by Brad Wilson
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With