public ActionResult GetVariants(Guid?ProductID, Guid?StyleClassID) { var Model = new List <VariantModel>(); var ProductVariants = _db.GetProductVariants(ProductID).ToList(); var Variants = _db.GetAllStyleTraitValues(StyleClassID).ToList(); Model = (from a in Variants.GroupBy(a => a.StyleTraitID).Select(grp => grp.First()) select new Models.VariantModel() { ID = a.StyleTraitID, Name = a.StyleTraitName, Description = a.StyleTraitDescription, Values = (from av in Variants where av.StyleTraitID == a.StyleTraitID select new Models.VariantValueModel() { ID = av.StyleTraitValueID, Value = av.StyleTraitValue, Selected = ProductVariants.Where(pa => pa.StyleTraitID == a.StyleTraitID).FirstOrDefault()?.StyleTraitValueID == av.StyleTraitValueID, SortOrder = av.StyleTraitValueSortOrder ?? 0 }).ToList() }).ToList(); if (Request.HttpMethod.ToUpper() == "POST") { return(Json(new { Html = RenderPartialViewToString("_ProductVariants", Model) })); } else { return(PartialView("_ProductVariants", Model)); } }