public IActionResult Index(int pageNo = 1, string category = "Все") { List <Food> foods; if (category == "Все") { foods = dbContext.Foods.ToList(); } else { Category cat = dbContext.Categories.FirstOrDefault(c => c.Name == category); foods = dbContext.Foods.Where(f => f.CategoryId == cat.Id).ToList(); } ListModelView <Food> page = ListModelView <Food> .CreatePage(foods, itemsPerPage, pageNo); foreach (Food food in page) { food.Category = dbContext.Categories.FirstOrDefault(c => c.Id == food.CategoryId); } ViewData["Category"] = category; ViewData["Categories"] = GetCategories(); if (Request.IsAjaxRequest()) { return(PartialView("_ListPartial", page)); } else { return(View(page)); } }
public IActionResult Index(int pageNo = 1, string category = "Все") { List <Food> foods; if (category == "Все") { foods = dbContext.Foods.Include(f => f.Category).ToList(); } else { Category cat = dbContext.Categories.FirstOrDefault(c => c.Name == category); foods = dbContext.Foods.Where(f => f.CategoryId == cat.Id).Include(f => f.Category).ToList(); } foods.Sort((f1, f2) => f1.Category.Name.CompareTo(f2.Category.Name)); ListModelView <Food> page = ListModelView <Food> .CreatePage(foods, itemsPerPage, pageNo); ViewData["Category"] = category; ViewData["Categories"] = GetCategories(); if (Request.IsAjaxRequest()) { return(PartialView("_ListPartial", page)); } else { return(View(page)); } }
public void setListFilesView(ListModelView listModelView) { cList = listModelView; }