/// <summary> /// Manual checkbox list generation /// http://stackoverflow.com/questions/12808936/how-do-i-render-a-group-of-checkboxes-using-mvc-4-and-view-models-strongly-type /// TODO: Improved checkbox list with /// https://www.nuget.org/packages/MvcCheckBoxList/ (http://mvccbl.com/Examples) or /// https://www.nuget.org/packages/Hex/ (http://staticdotnet.wordpress.com/hex/hex-creating-a-list-of-checkboxes/) /// </summary> /// <param name="recipient"></param> /// <returns></returns> private IList <FoodCategoryEditModel> GetFoodCategories(Recipient recipient) { var recipientSelectedCategoriesIds = new HashSet <int>(); foreach (var recipientCategory in recipient.FoodCategories) { recipientSelectedCategoriesIds.Add(recipientCategory.Id); } var foodCategories = this.foodCategoryService.GetAll(); var foodCategoriesList = new List <FoodCategoryEditModel>(); foreach (var foodCategory in foodCategories) { var foodCategoryModel = new FoodCategoryEditModel(); foodCategoryModel.Id = foodCategory.Id; foodCategoryModel.Name = foodCategory.Name; if (recipientSelectedCategoriesIds.Contains(foodCategory.Id)) { foodCategoryModel.IsChecked = true; } foodCategoriesList.Add(foodCategoryModel); } return(foodCategoriesList); }
public ActionResult AddFoodCategory(int vendorId) { var m = new FoodCategoryEditModel(); m.Subject.VendorId = vendorId; SetCategoryTypes(FoodCategoryTypeEnum.Entree); var uiresult = new UIResponse<FoodCategoryEditModel>(); uiresult.Subject = m; uiresult.HtmlResult = RenderPartialViewToString("AddEdit", m); return Json(uiresult, JsonRequestBehavior.AllowGet); }