public ActionResult Edit(int id = 0) { List <SelectListItem> parents = new List <SelectListItem>(); foreach (var parent in CategoryDALC.GetAll().Select(row => new { row.Id, row.Path })) { parents.Add(new SelectListItem { Text = parent.Path, Value = parent.Id.ToString() }); } CategoryViewModel model = new CategoryViewModel(); if (id == 0) { model.ParentCategories = parents; return(View(model)); } else { model = MapToCategoryViewModel(CategoryDALC.GetById(id)); model.ParentCategories = parents; return(View(model)); } }
public ActionResult Index() { var model = CategoryDALC.GetAll().Select(category => MapToCategoryViewModel(category)).ToList(); return(View(model)); }
public ActionResult CategoriesList() { var model = CategoryDALC.GetAll().Select(category => MapToCategoryViewModel(category)).ToList(); return(PartialView("_CategoriesList", model)); }