Kurkula
Kurkula

Reputation: 6762

Asp.Net MVC Getting Display Names

I am trying to get Display Name attributes in a model and display them in a loop. I am able to get Property name but unable to pull displayName attributes. Any help on logic would be highly appreciated. I tried debugging, adding watch to Model.GetType() and could not trace out attributes part.

 @foreach (PropertyInfo propertyInfo in Model.GetType().GetProperties())
            {
                <li>
                    <div>
                        @propertyInfo.Name
                    </div>
                </li>   
            }

Upvotes: 0

Views: 283

Answers (1)

Amit
Amit

Reputation: 15387

Try as

 @Html.DisplayNameFor(m => @propertyInfo.Name)

Upvotes: 2

Related Questions