public IActionResult EditGetCategorySpecs(int productId) { var product = _context.Products.Where(p => p.Id == productId).FirstOrDefault(); if (product == null) { return(NotFound()); } var category = _context.Categories.Where(c => c.Id == product.CategoryId).FirstOrDefault(); CategorySpecsViewModel ViewModel = new CategorySpecsViewModel(); List <CategorySpec> categorySpecs = new List <CategorySpec>(); var ProductSpec = _context.ProductSpecs.Where(ps => ps.ProductId == product.Id).ToList(); //foreach (var prodSpec in ProductSpec) //{ // categorySpecs.Add(_context.CategorySpecs.Where(cs => cs.Id == Id).FirstOrDefault()); //} ViewData["CategorySpecs"] = categorySpecs; return(PartialView(ViewModel)); }
public IActionResult GetCategorySpecs(int id) { CategorySpecsViewModel ViewModel = new CategorySpecsViewModel(); var categorySpecs = _context.CategorySpecs.Where(s => s.Category.Id == id).ToList(); ViewData["CategorySpecs"] = categorySpecs; return(PartialView(ViewModel)); }