binary code, binary, binary system-475664.jpg
0 0
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.

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

About Author

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Your email address will not be published. Required fields are marked *