Read Time:38 Second
public Task<IActionResult> Index(string searchString)
{
var listofItems=null;
if (!String.IsNullOrEmpty(searchString))
{
listofItems = _db.tabledatabase.Where(s => s.Title.Contains(searchString));
}
return View(listofItems);
}
Step 1.)
public Task<IActionResult> Index(string searchString)
{
//code
}
Explanation:- Define Action to perform task :: Index and parameter named searchString.
Step 2.)
var listofItems=null;
Explanation: Declare variable to hold reference. (list of object or records)
Step 3.)
if (!String.IsNullOrEmpty(searchString))
{
// todo
}
Explanation: Check if searchString must contain some value. (Not equal to empty or not equal to null.)
Step 4.)
listofItems = _db.tabledatabase.Where(s => s.Title.Contains(searchString));
Explanation: Fetch all the list from database table named tabledatabase using _db context and assigned to listofItems.
Step 5.)
return View(listofItems);
Explanation: Return listofItems to the View.