Search code examples
asp.net-mvcc#-4.0asp.net-mvc-5entity-framework-6asp.net-mvc-controller

How to filter results in controller operating on getting string from view in MVC5


I have a "video" search box in view that takes string input from user and pass back to controller...

Controller then operates on the string and returns data (Videos Name) to view.

I want to include the ".contain()" function to operate on string which contains the video.

Note: Controller returns exact same result as requested Name.

Code is as follows:

public ActionResult SearchVideos(string str)
{
  IQueryable<VideoDM> videodm = db.Video.Where(search => search.Title==str);
  if(str != null)
  {             
    return View(videodm);
  }
  else
  {
    string err = "No Video Found";
    return View(err);
  }
}

Is there a way to add contain() function after where() to tell the controller to return the result that contains the string "str"?


Solution

  • Add .contain() inside where clause.

    IQueryable<VideoDM> videodm = db.Video.Where(search => search.Title.Contains(str));