0

I am working in ASP MVC in a crud with search filters, the current one I have:

<span>Producto: </span><input type="text" name="producto" />

but i want to make it a dropdownlist try htmlHelper:

@Html.DropDownList("producto",(IEnumerable<SelectListItem>)ViewBag.NombreDelProducto,"--PRODUCTOS --")

And it gives me the following error:

'There is no ViewData item of type 'IEnumerable' that has the key 'producto'.

Controller:

 PharmcomEntities db = new PharmcomEntities();
public ActionResult Index()
{
    PharmcomEntities myentity = new PharmcomEntities();
    var getItem = myentity.Betances.ToList();
    SelectList list = new SelectList(getItem, "ID", "NombreDelProducto");
    ViewBag.NombreDelProducto = list;
    return View(db.Betances.ToList());
}
[HttpPost]
public ActionResult Index(DateTime start, DateTime end, int cliente, string producto)
{
    return View(db.pBetancesExample(start, end, cliente, producto));
}

View:

  <center>
<h1>Filtro de fecha</h1>
@using (Html.BeginForm("Index", "pBetances", FormMethod.Post))
{
    <span>Start date: </span><input type="date" name="start" />
    <span>End Date: </span><input type="date" name="end" />
    <span>Cliente: </span><input type="text" name="cliente" />
    @*<span>Producto: </span><input type="text" name="producto" />*@
    @Html.DropDownList("producto",(IEnumerable<SelectListItem>)ViewBag.NombreDelProducto,"-- PRODUCTOS --") 
    <input type="submit" value="generar filtros" />
}

0 Answers0