TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
osyris zosar
NA
289
26.9k
Trying to filter Database Data based on ID
Mar 5 2021 5:31 AM
Hello I am Trying to Filter Database Data base on ID but i cant get it to work;
Code:
public
async Task<ActionResult> Index(string searchString, string description)
{
var AllProducts = from m in _context.Products
select m;
List<
int
> IDList =
new
List<
int
>();
IDList.Clear();
int
count = 0;
filter base on Title
if
(!String.IsNullOrEmpty(searchString))
{
count++;
var FilterSearch = from Products in AllProducts
where Products.Title.Contains(searchString)
select Products.Id;
foreach (
int
Product in FilterSearch)
IDList.Add(Product);
}
filter based on description
if
(!String.IsNullOrEmpty(description))
{
count++;
var FilterDesc = from Products in AllProducts
where Products.ProductDescription.Contains(description)
select Products.Id;
foreach (
int
Products in FilterDesc)
IDList.Add(Products);
}
making sure that only data that have ID simulair appear
if
(IDList.Count != 0)
{
var filter2 = IDList.GroupBy(x => x)
.Where(g => g.Count() == count)
.Select(y => y.Key)
.ToList();
//under this line is what I think the problem
AllProducts = AllProducts.Where(x => x.Id.Equals(filter2));
}
return
View(await AllProducts.ToListAsync());
}
everything works except for this code on line 47:
AllProducts = AllProducts.Where(x => x.Id.Equals(filter2));
when I type something in both search fields (
description and
searchStrings)
It return back nothing
Only when both search fields are empty they show all the data
I just need the Data Database that have simulair ID's as those of the numbers in
filter2 list
How do i manage that?
Reply
Answers (
2
)
Pdf file content showing junk characters
Work on the side with ASP.NET MVC?