I am trying to make some filters that as I select one, I look for the records with that data and if I select another filter the list of records will be shortened. This is my code, it does not mark me any errors when compiling, but when I select any filter and I give it search, all the records disappear.
Vista:
@using (Html.BeginForm())
{
<p>
Salon: @Html.DropDownList("sln", " ")
Maestro:@Html.DropDownList("met", " ")
Especilidad:@Html.DropDownList("epc", " ")
Clave: @Html.TextBox("clv"," ")
Materia:@Html.DropDownList("mtr", " ")
Tutor:@Html.DropDownList("ttr", " ")
<input type="submit" value="Search" />
</p>
}
Driver
public ViewResult Index(int? page, string met, string ttr, string sln, string mtr, string epc, string clv)
{
const int pageSize = 20;
int pageNumber = (page ?? 1);
var esTs = db.EstudianteTs.Include(t => t.MaestrosT).Include(t => t.TutorT).Include(t => t.SalonT).Include(t => t.MateriaT).Include(t => t.EspecialidadT);
var maestro = db.EstudianteTs.OrderBy(t => t.MaestrosT.Nombre).Select(t => t.MaestrosT.Nombre).Distinct();
ViewBag.met = new SelectList(maestro);
var tutor = db.EstudianteTs.OrderBy(t => t.TutorT.Nombre).Select(t => t.TutorT.Nombre).Distinct();
ViewBag.ttr = new SelectList(tutor);
var salon = db.EstudianteTs.OrderBy(t => t.SalonT.Salon).Select(t => t.SalonT.Salon).Distinct();
ViewBag.sln = new SelectList(salon);
var materia = db.EstudianteTs.OrderBy(t => t.MateriaT.Nombre).Select(t => t.MateriaT.Nombre).Distinct();
ViewBag.mtr = new SelectList(materia);
var especialidad = db.EstudianteTs.OrderBy(t => t.EspecialidadT.Nombre).Select(t => t.EspecialidadT.Nombre).Distinct();
ViewBag.epc = new SelectList(epc);
esTs = db.EstudianteTs.Where(s => (mtr == null) || (s.MateriaT.Materia.Contains(mtr)))
.Where(s => (ttr == null) || (s.TutorT.Nombre.Contains(ttr)))
.Where(s => (epc == null) || (s.EspecialidadT.Nombre.Contains(epc)))
.Where(s => (met == null) || (s.MaestrosT.Nombre.Contains(met)))
.Where(s => (clv == null) || (s.Clave.Contains(clv)))
.Where(s => (sln== null) || s.SalonT.Salon.Contains(sln)));
return View(esTs.ToList().ToPagedList(pageNumber, pageSize));
}