public ActionResult Categories(Category category) { if (ModelState.IsValid) { // add to context BlogPostRepo.AddCategory(category); // submit changes // BlogPostRepo.SubmitChanges(); // redirect to category management index TempData[vinCMS.Infraestructure.Constants.VIEW_MESSAGE] = SUCCESS_CATEGORY_ADD; return RedirectToAction("categories"); } else { // return the same view var catViewModel = new AdminCategoryViewModel { NewCategory = category, PagedListCategories = new PagedList.StaticPagedList<Category>( BlogPostRepo.GetQueryableOrderedCategories().Skip(0).Take(CATEGORIES_PER_PAGE).ToList(), 0, CATEGORIES_PER_PAGE, BlogPostRepo.GetQueryableCategories().Count() ) }; // the view will show a series of validation error messages return View(catViewModel); } }
public ViewResult Categories(int page = 0) { // get IQueryable of categories StaticPagedList<Category> pagedListCategories = new StaticPagedList<Category>( BlogPostRepo.GetQueryableOrderedCategories().Skip(page*CATEGORIES_PER_PAGE).Take(CATEGORIES_PER_PAGE).ToList(), page, CATEGORIES_PER_PAGE, BlogPostRepo.GetQueryableCategories().Count()); // prepare view model AdminCategoryViewModel categoryViewModel = new AdminCategoryViewModel { NewCategory = new Category(), PagedListCategories = pagedListCategories }; // renders view return View(categoryViewModel); }