Difference between @Html.LabelFor and @Html.DisplayNameFor

1

I'm starting in ASP.NET MVC and doing a course where the teacher used to display data from a class different methods for displaying a given.

It uses @Html.LabelFor and @Html.DisplayNameFor . From what I have read in other forums% wc is used more for form creation, it displays the field contained in a class of a model , but if I use @Html.LabelFor it displays the same data

    
asked by anonymous 12.01.2018 / 17:25

1 answer

8

The DisplayNameFor() generates pure text with the title of that element, while LabelFor generates a tag label of the HTML with the title text, like this:

<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 on the page, the first is only meaningless text for the page / application.

That's why I say that you have to learn how it is and not how it appears. It's the same confusion people make about "working" and "being right," there's a lot of things wrong and it works, and people who learn wrong can not identify what's wrong because it feels right. But it just seems.

Thisisthebiggesttipyoucangetateverything.Whenthepersondoesnotseekthecorrectinformation,unliketheAPisdoingrightandseeking,livesineternal effect Dunning Krueger .

Both take the title determined by [DisplayName("")] " in the template, or the field name if it does not have the specified annotation.

See also .

    
12.01.2018 / 17:34