Karlo A. López
Karlo A. López

Reputation: 2668

Search code in C# .NET MVC is not working

Im trying to use the following code to get a list with the results of a search from another list. Heres what I've got:

    public ActionResult MedicosList(String order,String Search_Data)
                 {
                     var medicoEntity = new MedsEntities();
                     var lolo = from stu in medicoEntity.Medico select stu;
                     System.Diagnostics.Debug.WriteLine("NO HAY D:");
                     {
                         lolo = lolo.Where(stu => stu.NOMBRE.Contains(Search_Data.ToUpper()) || stu.TIPO.ToUpper().Contains(Search_Data.ToUpper()));
                         System.Diagnostics.Debug.WriteLine("SI HAY :D");

                     }

 return View(lolo);
    }

VIEW:

@using (Html.BeginForm())
{
    <p>
        Buscar: @Html.TextBox("Search_Data", ViewBag.FilterValue as string)
        <input type="submit" value="Buscar" />
    </p>
}

The problem is that the table is always filled with all the list, not with the results.

Thanks.

Upvotes: 0

Views: 411

Answers (1)

Mark
Mark

Reputation: 182

Why don't you try filtering for the object immediately? Also, I'm not sure why you have a second set of curly braces. If the MedsEntities function is a DataContext type, I believe when you are passing lolo to the View, it is still a Queryable. Maybe try this:

public ActionResult MedicosList(String order,String Search_Data)
{
    var medicoEntity = new MedsEntities();
    System.Diagnostics.Debug.WriteLine("NO HAY D:");
    var lolo = medicoEntity.Medico.Where(stu =>
                   stu.NOMBRE.Contains(Search_Data.ToUpper()) ||
                   stu.TIPO.ToUpper().Contains(Search_Data.ToUpper())
               ).ToList();
    System.Diagnostics.Debug.WriteLine("SI HAY :D");
    return View(lolo);
}

Upvotes: 1

Related Questions