Load a table with data

2

Working in ASP.NET MVC 5 I want to populate a table with data that a list brings me.

table HTML

<table class="table">
    <tr>
        <td>ProveedorId</td>
        <td>Razón Social</td>
        <td>Documento Identidad</td>
        <td>Número documento</td>
        <td>Dirección</td>
        <td>Teléfono</td>
        <td></td>
        <td></td>
    </tr>
</table>

Controller

public ActionResult Index()
    {
        List<ProveedorDto> list = SdProveedor.GetProveedor().ToList();
        return View(list);
    }
    
asked by Pedro Ávila 13.02.2017 в 20:47
source

3 answers

2

When you have a question like this, add your model to give better answers: D

@model List<ProveedorDto>
<table class="table">
   <tr>
        <td>ProveedorId</td>
        <td>Razón Social</td>
        <td>Documento Identidad</td>
        <td>Número documento</td>
        <td>Dirección</td>
        <td>Teléfono</td>
        <td></td>
        <td></td>
    </tr>   
@foreach (var item in Model)
{
    <tr>        
        <td>@item.ProveedorId</td>
        <td>@item.razonsocial</td>
        <td>@item.documentoDeIdentidad</td>
        <td>@item.numeroDeDocument</td>
        <td>@item.direccion</td>
        <td>@item.telefono</td>
        <td></td>
        <td></td>
    </tr>
}
    
answered by 13.02.2017 в 20:56
1

I did it in the following way Controller

public ActionResult Index()
    {
        List<ProveedorDto> list = SdProveedor.GetProveedor().ToList();
        ViewBag.ListarProveedor = list;
        return View(list);
    }

View

<body>
<table class="table">
    <tr>
        <td>ProveedorId</td>
        <td>Razón Social</td>
        @*<td>Documento Identidad</td>*@
        <td>Número documento</td>
        <td>Dirección</td>
        <td>Teléfono</td>
        <td></td>
        <td></td>
    </tr>
    @foreach (var row in ViewBag.ListarProveedor)
    {
        <tr>
            <td>@row.ProveedorId</td>
            <td>@row.RazonSocial</td>
            <td>@row.NumeroDocumento</td>
            <td>@row.Direccion</td>
            <td>@row.Telefono</td>
        </tr> 
    }
</table>

    
answered by 13.02.2017 в 21:19
0

for your example if the model is called Supplier the code could be like the following:

@model IEnumerable<Models.Proveedor>
<table class="table">
    <tr>
        <td>ProveedorId</td>
        <td>Razón Social</td>
        <td>Documento Identidad</td>
        <td>Número documento</td>
        <td>Dirección</td>
        <td>Teléfono</td>
        <td></td>
        <td></td>
    </tr>
@foreach (var item in Model) {
<tr>
        <td>
  @Html.DisplayFor(modelItem => item.ProveedorId)
        </td>
      <td>
  @Html.DisplayFor(modelItem => item.razonSocial)
        </td>
      <td>
  @Html.DisplayFor(modelItem => item.docId)
        </td>
      <td>
  @Html.DisplayFor(modelItem => item.numId)
        </td>
      <td>
  @Html.DisplayFor(modelItem => item.direccion)
        </td>
      <td>
  @Html.DisplayFor(modelItem => item.telefono)
        </td>
</tr>
}
</table>
    
answered by 14.02.2017 в 15:00