Pass a list from the action in my view in MVC 5

0

I have the following query in the Action

Then in my Vista I try to show the table in the following way using @ item.cantRevised

I would also like to know if in MVC 5 you can pass a list in this case consult with LINQ through the action without going through the Model and Affect the View

Thank you, for your help and comments, I hope that I have been as specific and clear as possible

    
asked by Vajra 16.06.2018 в 20:44
source

1 answer

0
  • From the model:
  • Controller:

     return View(tabla.ToList());
    

    View:

    @Model List<dynamic>
    

    To access a value:

    @item.ND
    
  • From the viewBag:
  • Controller:

    ViewBag.est = tabla.ToList();
    

    View:     var table = (List) ViewBag.est;

    To access a value:

    @foreach(var item in tabla)
     <td>item.ND</td>
    

    The selection to be dynamic does not have autocomplete in the view, so we will not know if we have written all the fields well until we execute the view. To avoid this it would be necessary to create a model and return it in the select and in the view, put it as a model.

        
    answered by 17.06.2018 в 18:40