html.labelfor

Why should I use LabelFor in MVC?

社会主义新天地 提交于 2019-12-10 12:28:05
问题 Why should I use LabelFor instead of <label> ? eg. @Html.LabelFor(model => model.FirstName) @Html.DisplayFor(model => model.FirstName) vs <label for="FirstName">First Name</label> @Html.DisplayFor(model => model.FirstName) Further to the above, @p.s.w.g has covered the DRY aspect of this question. I would also like to know if it helps with localization. ie. Different labels based on the current language setting. 回答1: Well, if you've decorated your models with the DisplayNameAttribute like