Using MVC3 for the first time, so sorry for the noob-like question.
I’m trying to annotate my data model for the UI layer. In my model, I have the following
[DisplayName("First Name")]
public string firstName { get; set; }
When I create a view based on the Details/Delete scaffold, it generates the following:
<div class="display-label">firstName</div>
<div class="display-field">
@Html.DisplayFor(model => model.firstName)
</div>
This does not, obviously, use my annotated model. When I create a view based on the Create/Edit scaffold, it generates this HTML:
<div class="editor-label">
@Html.LabelFor(model => model.firstName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.firstName)
@Html.ValidationMessageFor(model => model.firstName)
</div>
Because it’s using the @Html.LabelFor, it ultimately uses my annotated model as I anticipated.
Obviously I can see the common thread – the first two are editable, the second two are readonly. I cannot imagine why they would save me the trouble on two of them, and not on the others, but I’m sure there has to be a reason, right?
So if there IS a reason, is my only solution to manually go through each of the views & change the content from firstName to First Name?
I don’t know why they did that either, but you can create your own display template for objects as explained here that uses your annotation.