public IActionResult SelectByCategory() { var model = new AdvertisementsCategoryFormModel { Categories = this.category .All() .Select(c => new SelectListItem { Text = c.Name, Value = c.Id.ToString() }) }; return(View(model)); }
public IActionResult SelectByCategory(AdvertisementsCategoryFormModel model) { if (!ModelState.IsValid) { model.Categories = this.category .All() .Select(c => new SelectListItem { Text = c.Name, Value = c.Id.ToString() }); return(View(model)); } return(RedirectToAction(nameof(AllByCategory), new { categoryId = model.CategoryId })); }