public ActionResult CheckboxList(CategoryPickerViewModel model) { var selectedIds = model.CategoryCheckboxes.Where(c => c.IsSelected).Select(c => c.Category.CategoryId); return(View("PickResults", selectedIds)); }
public override void ViewDidLoad() { base.ViewDidLoad(); NavigationItem.Title = "Product"; var model = new CategoryPickerViewModel(_product); CategoryPicker.Model = model; if (isNewProduct) { //Will start in edit mode NavigationItem.SetHidesBackButton(true, true); NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Done, HandleDoneButtonPressed); categoryBoarder.Hidden = true; _product.Category = 0;//Set to first in list } else { NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Edit, HandleEditButtonPressed); nameField.Enabled = false; priceField.Enabled = false; quantityField.Enabled = false; CategoryPicker.Hidden = true; categoryBoarder.Hidden = false; nameField.Text = _product.Name; priceField.Text = _product.Price.ToString(); quantityField.Text = _product.Quantity.ToString(); categoryName.Text = Enum.GetName(typeof(ProductCategory), _product.Category); } }
public ActionResult CheckboxList(CategoryPickerViewModel model) { //use Linq query to select ticked categories var selectedIds = model.CheckboxItems .Where(c => c.IsSelected) .Select(c => c.Category.CategoryId); return(View("PickResults", selectedIds)); }
public ActionResult CheckboxList() { var model = new CategoryPickerViewModel(); model.CategoryCheckboxes = (from category in CategoryRepository.GetAll() select new CategoryCheckBoxItem { Category = category, IsSelected = false }).ToList(); return(View(model)); }
public ActionResult CheckboxList() { var model = new CategoryPickerViewModel(); // convert the list of category objects to CategoryCheckBoxItems using LINQ model.CategoryCheckboxes = (from category in CategoryRepository.GetAll() select new CategoryCheckBoxItem { Category = category, IsSelected = false }).ToList(); return(View(model)); }
public ActionResult CheckboxList() { //load list of categories then convert them to ViewModel with Linq to create anon types var model = new CategoryPickerViewModel { CheckboxItems = ( from category in CategoryRepoStub.GetAll() select new CategoryCheckboxItem { Category = category, IsSelected = false } ).ToList() }; return(View(model)); }
public async Task <ActionResult> Index(string id, string categoryId) { long?catId; try { catId = long.Parse(categoryId); } catch { catId = null; } var categories = await _catViewModelBuilder.GetCategoriesAsync(catId, levels : 99).ConfigureAwait(false); var viewModel = new CategoryPickerViewModel { SearchCriteria = "", Categories = categories, ControlId = id }; return(View(viewModel)); }