A set of technologies in .NET for building web applications and web services. Miscellaneous topics that do not fit into specific categories.
Hi @Dean Everhart ,
50 models = models.Where(s => s.Text.Contains(searchString)); <- "s.Text" is underlined in green after adding pagination.
If you move the mouse over the "s.Text", you can see it will show the CS8602 nullable warnings, it means this property might be null. Because the Text property is nullable: public string? Text { get; set; }
To disable this warning, you can change the Text property to not-null or add a missing null check. You can try to use the following code:
models = models.Where(s => s.Text != null && s.Text.Contains(searchString));
52 // || s.Number.Contains(searchString) <- had to comment out this line for code to work. It was stating that it couldn't search on a number?
The Contains method is a String class's method, so, you can't directly use it with the Int number. If you want to check whether the number contains special number, you can convert it to a String, then use the Contains method. Code like this:
models.Where(s => s.Number.GetValueOrDefault().ToString().Contains(searchString));
To combine them, the query statement as below:
models.Where(s => (s.Text != null && s.Text.Contains(searchString)) || s.Number.GetValueOrDefault().ToString().Contains(searchString));
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion