Reputation: 59
string Categoriesjson = @"[
{
'cat_id' : 1,
'name': 'HTML',
'desc': 'WebDesign',
'img': 'Assets/sawirada/html-flat.png',
}];
I have this JSON data i Converted to a list, I Want to Pass the Category id to a courses page and list the courses that match this category Id using LINQ.
string Coursesjson = @"[
{
'id' : 1,
'cat_id' : '2',
'name': 'Learn HTML',
'date': '2017-10-19',
'img': 'Assets/sawirada/phpmysql.jpg',
}];
Upvotes: 0
Views: 89
Reputation: 325
Deserialize the Coursejson to a list, and use LINQ to get the matching courses:
var passedCatId = 1;
List<Course> allCourses = JsonConvert.DeserializeObject<List<Course>>(Coursejson);
List<Course>filteredCourses = allCourses.Where(c => c.cat_id == passedCatId).ToList();
Upvotes: 1