// GET: Backend/ProdColor public ActionResult Index(int id) { ProductColorVIewModel pcvm = new ProductColorVIewModel(); var pd = db.Products.Find(id); pcvm.ProductID = pd.ProductID; pcvm.ProductName = pd.ProductName; ViewBag.productcolor = db.Colors; return(View(pcvm)); }
public ActionResult ProdColorJson(int id) { List <ProductColorVIewModel> pcvmlist = new List <ProductColorVIewModel>(); var ps = db.ProductColors.Where(x => x.ProductID == id).OrderByDescending(x => x.ProductColorID); var c = db.Colors; foreach (var item in ps) { ProductColorVIewModel psvm = new ProductColorVIewModel { ProductColorID = item.ProductColorID, ProductID = item.ProductID, ColorID = item.ColorID, CreateDate = item.CreateDate, ColorName = c.Where(x => x.ColorID == item.ColorID).FirstOrDefault().ColorName, PhotoID = (item.PhotoID == null ? 0 : item.PhotoID), }; pcvmlist.Add(psvm); } return(Json(pcvmlist, JsonRequestBehavior.AllowGet)); }