public async Task <IActionResult> AddCategory(Category model) { //Add new Category List <Alert> lstAlerts = new List <Alert>(); if (ModelState.IsValid) { model.User = await _userManager.GetUserAsync(User); if (_homeBusiness.AddCategory(model)) { lstAlerts.Add(new Alert("success", "Categoría registrada correctamente.")); } } else { foreach (var error in ModelState.Values.Where(x => x.Errors.Count > 0)) { foreach (var msg in error.Errors) { lstAlerts.Add(new Alert("warning", msg.ErrorMessage)); } } } var tempAlerts = JsonConvert.SerializeObject(lstAlerts.ToList()); TempData[SessionKeys.Alerts] = tempAlerts; return(RedirectToAction("Index")); }