Reputation: 6762
I am trying to display model
Property names in my View
instead of values.
For example if my model
has properties name
, address
and phone
as properties, I want to display the same property names in my view. Could you please let me know how to do that?
What I tried is I stepped into the code in debug mode and saw Model[0]
item and found all property names there and I am struck from there.
Upvotes: 0
Views: 41
Reputation: 1469
Try
@foreach (PropertyInfo propertyInfo in Model.GetType().GetProperties())
{
@propertyInfo.Name
}
Upvotes: 1
Reputation: 25231
By default, you can just use Html.DisplayNameFor(m => m.SomeProperty)
as, unless you have specified display names for these properties, they will default to the property name.
Upvotes: 1