skip to Main Content

This Will return only when the user is available at the same case

 public async Task<IActionResult> Index(string UserSearch)
    {
        ViewData["GetUserDDetails"] = UserSearch;

        var UserQuery = from x in _context.Users select x;
        if (!string.IsNullOrEmpty(UserSearch))
            {
            UserQuery = UserQuery.Where(x => x.Username.Contains(UserSearch) || x.Email.Contains(UserSearch));
        }
        return View(await UserQuery.AsNoTracking().ToListAsync());
    }

2

Answers


  1. Use .ToLower() or .ToUpper() on both the query value and the subject value.

    x => x.Username.ToLower().Contains(UserSearch.ToLower()) || ...
    
    Login or Signup to reply.
  2. Try this:

     public async Task<IActionResult> Index(string UserSearch)
     {
        ViewData["GetUserDDetails"] = UserSearch;
        var UserQuery = from x in _context.Users select x;
    
        if (!string.IsNullOrEmpty(UserSearch))
        {
            UserQuery = UserQuery.Where(x => x.Username.ToUpper().Contains(UserSearch.ToUpper()) || x.Email.ToUpper().Contains(UserSearch.ToUpper()));
        }
        return View(await UserQuery.AsNoTracking().ToListAsync());
     }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search