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

asp.net-mvc asp.net-mvc-5 asp.net-mvc-controller c#-4.0 entity-framework-6

Question

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"?

1
0
2/11/2015 8:18:25 AM

Accepted Answer

Add .contain() inside where clause.

IQueryable<VideoDM> videodm = db.Video.Where(search => search.Title.Contains(str));
1
2/11/2015 8:59:18 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow