1
I have a view on Asp.net mvc as follows
var Maquina = Model.ListMaquinas;
@Html.DisplayNameFor(x => Maquina.Property1 )
@Html.DisplayNameFor(x => Maquina.Property2 )
...
@Html.DisplayNameFor(x => Maquina.Property100 )
Everything works fine.
But as I have many fields I decided to make a foreach in the following way:
var Maquinas = Model.ListaMaquinas;
@foreach( System.Reflection.PropertyInfo item in Maquinas.GetType().GetProperties())
{
@Html.DisplayNameFor(x => Maquinas.GetType().GetProperty(item.Name) )
}
But so Displaynamefor is not working I’m missing at some point? Could someone help me?
You are wrong because it is the variable item that you should use and maybe by using reflection.
– novic
I tried to use it like this: @Html.Displaynamefor(x => @item.Name) but just print Namenamename...
– Accorsi
It was answered according to the question the answer was useful ?
– novic