How to Use DisplayFor to Display Text from EF Core Data Annotation in MVC and Components

Question: #DisplayFor is not working in #MVC Asp.Net Core View and the #Component, what am I doing wrong?

I have my #Modal #Class defined as below:

 public sealed partial class CompositionQuestionaire

        public int Id { get; set; }
        [Display(Name = "Have there been any changes in household composition in the last twelve months?")]
        public bool AnyChangesInLast12Months { get; set; }

And I am trying to render the Display Name as shown below:

<div class="col-6">
 @Html.DisplayFor(a => a.CompositionQuestionaire.AnyChangesInLast12Months)                              

The above-shown #DisplayFor @HTML Tag Helper in MVC is not working, what am I doing wrong?

Login to See the Rest of the Answer

Answer: Use the @Html.DisplayNameFor instead of DisplayFor, I hope this helps you.

Helpful Resources:


Lidia said:

How to contact you?

Posted On: September 17, 2022 13:18:04 PM
Mark said:


Posted On: September 17, 2022 13:17:36 PM

© 2024 - ErnesTech - Privacy
E-Commerce Return Policy