Filter records with dropdownlist

0

Good morning comrades I am trying to filter the records by means of a dropdownlist but at the moment of clicking the button it only refreshes the page but does not do any search.

controller

    public ViewResult Index(string estado, int? page)
        {

var estados = db.Representantes.OrderBy(p => p.EstadosT.Name).Select(p => p.EstadosT.Name).Distinct();

                if (!String.IsNullOrEmpty(estado))
                {
                   representante = db.Representantes.Where(s => s.EstadosT.Name.Contains(estado));

                }

                ViewBag.EstadosT = new SelectList( estados);
     return View(representante .ToList().ToPagedList(pageNumber, pageSize));
            }

view

@using (Html.BeginForm ()) {

    States: @ Html.DropDownList ("StatesT", "All")         

}

    
asked by senseilex 03.11.2017 в 19:02
source

1 answer

0

Your DropDownList is called EstadosT but in your action you expect a value with the name of estado . Rename your control to estado in order to receive the values in the action:

@using(Html.BeginForm()) {
 Estados: @Html.DropDownList("estado", "All")
}

Remember that the names of the control must be equal to the names of the action parameters in order to receive the value.

    
answered by 03.11.2017 / 20:45
source