public ActionResult Posts(int?CatId, string[] searchTag, string searchString) { newsList.Clear(); ViewBag.CurrentSearchTag = searchTag; ViewBag.CurrentSearchString = searchString; var news = repo.GetAllNews(); var categories = repo.GetAllCategory(); var tags = repo.GetAllTags(); newsList.Clear(); foreach (var post in news) { newsList.Add(new NewsViewModel() { News = news, Id = post.Id, Tittle = post.Tittle, Description = post.Description, Body = post.Body, PostedDate = post.PostedDate, Modified = post.Modified, Category = post.Category, CategoryID = post.CategoryID, NewsTags = post.NewsTags, AllCategory = categories, AllTags = tags }); } if (!String.IsNullOrEmpty(searchString)) { newsList = newsList.Where(n => n.Tittle.ToLower().Contains(searchString.ToLower()) || n.Description.ToLower().Contains(searchString.ToLower()) || n.Category.CategoryName.ToLower().Contains(searchString.ToLower())).ToList(); } //category filter if (CatId != null) { newsList.Clear(); var newscatfilter = repo.CategoryFilter(CatId); foreach (var post in newscatfilter) { newsList.Add(new NewsViewModel() { News = news, Id = post.Id, Tittle = post.Tittle, Description = post.Description, Body = post.Body, PostedDate = post.PostedDate, Modified = post.Modified, Category = post.Category, CategoryID = post.CategoryID, NewsTags = post.NewsTags, AllCategory = categories, AllTags = tags }); } } ViewBag.AllCategory = categories; CategoryList(); ViewBag.AllTags = tags; return(PartialView("Posts")); }