Suppose I have a class called Solicitud
and inside I have the following attributes:
int id
int Nro
string Tipo
IList<Cuentas> cuentas
Note: accounts are linked by%% of request%
What I want to do is call a field belonging to class id
and show it in Cuenta
:
Something like this:
<tbody>
@foreach (var item in Model)
{
<tr role="row">
<td class="col-xs-1 col-sm-1 col-md-1 col-lg-1">
@Html.DisplayFor(modelItem => item.id)
</td>
<td class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
@Html.DisplayFor(modelItem => item.Nro)
</td>
<td class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
@Html.DisplayFor(modelItem => item.Cuentas.Select(x => x.Descripcion)) ????
@Html.DisplayFor(modelItem => item.Cuentas[0].Descripcion) ????
</td>
</tr>
}
</tbody>
The syntax that I wrote does not know if it's the correct one because at the moment I'm not with Visual Studio at hand. I did it a little bit of memory. But what I want to reflect is the idea of what I want to do.
When I execute the project I get an error that only allows me to show fields, properties, etc. I think it has to do with what DataTable
is a Cuentas
. But when I load an object in the list of requests in the Controller , when I go through the records of is to list. For each record I have: List
, id
, nro
, or the list of tipo
. That only brings me a single record since it is related to the Cuentas
of Request. And there I can see the field id
.
But when I want to do the same in the View it does not recognize me. It does not leave me Descripcion
. It only accepts simple attributes to show.
The question is, how can I show in a DataTable
a field that is inside a DataTable
object that is part of the List
object that passes to View ?