List data in ASP.NET view c #

1

I have the following method where I bring the data from the database

//Traer categoria
        public List<categoria> listar()
        {
            var cate = new List<categoria>();

            using (var ctx = new ACME())
            {
                cate = ctx.categoria.ToList();

            }

            return cate;
        }

I'm seeing it in the following way

public ActionResult Categoria()
        {
            return View(ct.listar());
        }

In the view I add the model (I do not know if it is right or wrong at this point)

@model LicoreraDist.Models.ACME

and finally I try to show the data I have

@foreach (var m in Model.categoria)
{
  <ol class="list-group list_of_items">
     <li class='list-group-item'><div class='text_holder'> @m.categoria1<div 
     class='btn-group pull-right'><button class='delete btn btn- 
     warning'>Borrar</button><button class='edit btn btn- 
     success'>Editar</button></div></div><br /></li>
  </ol>
}

According to me "it's okay", but when I try to see the result on the website it shows me the following:

El elemento de modelo pasado al diccionario es de tipo 'System.Collections.Generic.List'1[LicoreraDist.Models.categoria]', pero este diccionario requiere un elemento de modelo de tipo 'LicoreraDist.Models.ACME'.
Descripción: Excepción no controlada al ejecutar la solicitud Web actual. Revise el seguimiento de la pila para obtener más información acerca del error y dónde se originó en el código. 

Detalles de la excepción: System.InvalidOperationException: El elemento de modelo pasado al diccionario es de tipo 'System.Collections.Generic.List'1[LicoreraDist.Models.categoria]', pero este diccionario requiere un elemento de modelo de tipo 'LicoreraDist.Models.ACME

The error is yes or yes in the reference to the model in the view, what would my error be in specific?

Thank you very much

    
asked by Baker1562 17.04.2018 в 05:43
source

1 answer

1

Your problem is that you are passing a list in sight and you are receiving an object.

Probably replacing the line

@model LicoreraDist.Models.ACME

By

@model IEnumerable<LicoreraDist.Models.ACME>

That way it should work, greetings

    
answered by 17.04.2018 / 05:57
source