Problems with filtering in ASP.NET core razor

asp.net core paging sorting filtering
asp.net core mvc with ef core - sort, filter, paging
asp.net core razor paging
asp.net core search filter
implement paging in asp.net mvc core
asp.net core web api paging sorting filtering
asp net core razor pages dropdownlist
checkbox in asp net core razor pages

I'm new to c# ASP.NET razor pages and I'm using the sample in Microsoft traing to build an app. The code below works when I attempt to search an item like "Godzilla" from the movie table. The problem is that if Itry to search on "Godzilla", "GhostBusters" and "Kazzoky" it returns null.

so if searchString is "Godzilla", i get a result and same for "Kazzoky" and "Ghostbusters" biut when I pass "Godzilla,Kazzoky,Ghostbusters" as searchString, the result is a blank page.

Please help!!

public async Task OnGetAsync()
{
    var movies = from m in _context.Movie
                 select m;
    if (!string.IsNullOrEmpty(SearchString))
    {
        movies = movies.Where(s => s.Title.Contains(SearchString));
    }

    Movie = await movies.ToListAsync();
}

I have tried

parts = parts.Where(s =>searchString.Contains(s.Title)); //didnt work

I have also tried movies = movies.Where(s => s.Title.Contains(Where(s=>SearchString.Contains(s.Title))));

but it threw and exception...

Try with this one.

movies = movies.Where(s => SearchString.Contains(s.Title));

3.01update: Filter methods for Razor Pages in ASP.NET Core � Issue , OnResultExecutingAsync you'll cover Razor pages. At least according to the docs Filter methods for Razor Pages in ASP.NET Core� I'm following Working with Data in ASP.NET Core tutorial in Microsoft documentation,(Sort, filter, page, and group section) but I have a hard time trying to figure out how the following code works(I'm new to razor pages and asp.net core). this is the PageModel for students index page.

If your search is comma separated, you need to split it up:

var searchTerms = SearchString.Split(',');

movies = movies.Where(s => searchTerms.Contain(s.Title));

Add a result filter for razor pages � Issue #34 � microsoft , If you run into problems you can't solve, download the completed app and compare that code to what you created by following the tutorial. This� By Rick Anderson. Razor Page filters IPageFilter and IAsyncPageFilter allow Razor Pages to run code before and after a Razor Page handler is run. Razor Page filters are similar to ASP.NET Core MVC action filters, except they can't be applied to individual page handler methods.

Thanks all for your inputs. I have solved the problem.

movies = movies.Where(s => SearchString.Contains(s.Title));

But I was testing it against a wrong dataset. For example a single search on "Gho" will return Ghostbusters but that is fine when you only want to search part of a title because you couldn't remember fully.

I was making this assumption and thats why i was having this problem.

Thanks everyone for your contributions, I really appreciate.

Part 3, Razor Pages with EF Core in ASP.NET Core, This was a big issue in MVC filter implementations. Register Razor Page Filter. Next step is to register your page filter in Asp.Net Core pipe line. I'm trying (hoping?) to use exception filtering in a ASP.NET Web Pages / Razor website. I'm using C# 7 with Microsoft.AspNet.Razor 3.27 and Microsoft.AspNet.WebPages 3.2.7, but I'm still getting errors when trying to use the keyword 'when' in a try catch block, like:

Filters for Asp.Net Core Razor Pages, I have an ASP.NET Core MVC Web Applications with Razor Views and Razor Pages. In this case, the last ones are the login and account� "Razor Pages is a new aspect of ASP.NET Core MVC that makes coding page-focused scenarios easier and more productive." and "Razor Pages is the recommended approach to create a new Web UI app with ASP.NET Core 2.0." It seems razor page is newer than the ASP.Net MVC way. But my problem is the same with the below post comes from "Stackoverflow"

How to Create a Filter for Razor Pages and Razor Views in ASP , Sorting, filtering, paging, and grouping - EF Core with Razor Pages If you run into problems you can't solve, download the completed app for this stage. There's nothing ASP.NET Core-specific in this base library, so you're free to use it in any .NET Standard 2.0 app. However, there's an additional library, Microsoft.FeatureManagement.AspNetCore , that does depend on ASP.NET Core, which contains various helper functions and extension methods for working with feature flags.

ASP.NET CORE - Sorting, filtering, paging, and grouping, ASP.NET Core Razor Pages make building web applications simpler, but The only problem I found was working out how to do all the things I used My application uses AJAX to fill a user-selectable filter, and I wasn't sure� Add Filtering (Search Box) to the Razor Page We can allow filtering by putting the text box for a user to search his data based on any present on the Index.cshtml page (Razor Page). The user should be able to search the column, once he enters the search term in the search box and clicks on the button on the page.

Comments
  • Do you have data in the database?
  • Yes Erik. It's just the syntax to search multiple items using IQueryable that I can't find
  • Where does SearchString come from?
  • You are doing it wrong.It should be SearchString.Contains(s.Title)
  • Cannot duplicate your problem with the code you've provided.
  • I've tried that already and it didn't work, I just omitted it so I don't cause much confusion. Thanks
  • I've also tried movies = movies.Where(s => s.Titke.Contains(Where(s=>SearchString.Contains(s.Title)))); but it threw and exception...
  • It should work with SearchString.Contains(s.Title) I have done it so many times. Debug your code and see if searchstring is correct. Also check if you have proper records in the db.
  • Its a little bit like trying to run a subquery against specific a field in a query....