It appears that if you just use Html.DisplayFor(model => model)
with no templates for a Details view, the resulting markup will look something like this:
<div class="display-label">first name</div>
<div class="display-field">Dan</div>
<div class="display-label">last name</div>
<div class="display-field">M</div>
<div class="display-label">email</div>
<div class="display-field">danm@fakedomain.com</div>
This has a fair degree of flexibility. If you create CSS classes for display-label
and display-field
, you can do quite a bit, but what if I wanted to change it to something like this?
<p>
<span class="display-label">first name</span>:
<span class="display-field">Dan</span>
</p>
<p>
<span class="display-label">last name</span>:
<span class="display-field">M</span>
</p>
<p>
<span class="display-label">email</span>:
<span class="display-field">danm@fakedomain.com</span>
</p>
Note that now the attribute-value pairs now appear side-by-side (instead of on separate lines) and there is a colon after each attribute.
Is there any way to create a custom template that will be repeated for each attribute-value pair when a details view is scaffolded?
I m not talking about a specific template for a model (e.g., a Person
template) or a template for a particular property (e.g., an EmailAddress
template). I want something that just lets me describe how an attribute-value pair looks, then DispalyFor()
should automatically repeat that template for each property in my model or view model.