I'm learning about ASP.NET Core and I've been a few days stuck in the following hopefully I could help.
In my controller I have the following '
public IActionResult Index(string searchString)
{
ViewData["FiltroActual"] = searchString;
var viewmodel = new ProductoCategoria(); //collecion de dos entidades para poder pasar dos viewmodels a la vista
viewmodel.Productos = from p in _context.Producto
select p;
viewmodel.Categorias = from c in _context.Categoria
select c;
if (!String.IsNullOrEmpty(searchString))
{
viewmodel.Productos = viewmodel.Productos.Where(s =>
s.Titulo.ToUpper().Contains(searchString.ToUpper()));
}
return View(viewmodel);
}
In the view I have the following
model VendoTest1.Models.ProductoIndexData
<form asp-action="Index" method="get" >
<div class="col-sm-4" style="padding:0px 8px 0px 0px;">
@Html.DropDownListFor(model => model.Categorias, new SelectList(Model.Categorias, "IdCategoria", "Nombre"), "-Categoria-")
</div>
<div class="col-sm-6">
<div class="row">
<input id="input-buscar-principal" class="col-xs-11" type="text" name="searchString" placeholder="que estas buscando?..." value="@ViewData["FiltroActual"]"/>
<input type="submit" value="Buscar" class="btn btn-default" />
</div>
</div>
</form>
How can I send the id value of the dropdownlist to the controller?