The DisplayNameFor()
generates a pure text with the title of that element, already the LabelFor
generates a tag label
HTML with the title text, thus:
<label for="Campo">Título</label>
What will appear on the page is the same, but the semantics within the page is very different. The second identifies what is that on the page, the first is only a meaningless text for the page/application.
That’s why I say you have to learn what it looks like, not how it looks. It’s the same confusion that people make with "working" and "being right," there’s a lot of stuff that’s wrong and works, and people who learn wrong can’t identify that it’s wrong, because it feels right. But it just seems.
This is the biggest tip you can get in everything. When one does not seek the right information, unlike the AP is doing right and seeking, lives in eternal Dunning Krueger effect.
Both take the title determined by [DisplayName("")]
template, or field name if you do not have the specified annotation.
See also.
I would add that both will use the annotaion date
[DisplayName("")]
of the attribute and if it does not exist, it uses its own name.– Leandro Angelo
@Leandroangelo done! Thank you.
– Maniero