コード例 #1
0
        public ActionResult CellCalculate(int id)
        {
            var category = _db.Categories.SingleOrDefault(x => x.CategoryId == id);
            var productViewModels = _db.Products.Where(x => x.CategoryId == id).Select(x => new ProductViewModel { ProductId = x.ProductId, Name = x.Name, Price = x.Price, Quantity = 1, Total = x.Price * 1, CategoryId = x.CategoryId });

            var categoryViewModel = new CategoryViewModel { CategoryId = category != null ? category.CategoryId : 0, Name = category != null ? category.Name : "", ProductViewModels = productViewModels };

            return View(categoryViewModel);
        }
コード例 #2
0
        //Get
        public ActionResult SelectListByModel(int id)
        {
            var category = _db.Categories.SingleOrDefault(x => x.CategoryId == id);
            var products = _db.Products.Where(x => x.CategoryId == id);

            var categoryViewModel = new CategoryViewModel { CategoryId = category.CategoryId, Name = category.Name, Products = products };

            return PartialView("_SelectListByModel", categoryViewModel);
        }