public ActionResult SaveNewCategory() { //save the new category if (!Authorize()) { return(RedirectToAction("RedirectByUser", "Home")); } CategoryDal ctgyDal = new CategoryDal(); Category newCategory = new Category { Type = Request.Form["Type"].ToString() }; ModelState.Clear(); TryValidateModel(newCategory); if (ModelState.IsValid) { try { ctgyDal.Categories.Add(newCategory); ctgyDal.SaveChanges(); } catch (DbUpdateException) { //TODO: show error message in client side ViewBag.addNewCategoryError = "התרחשה שגיאה בהוספת הקטגוריה"; } } else { ViewBag.addNewCategoryError = "הזן קטגוריה תקינה!"; } List <Category> categories = ctgyDal.Categories.ToList <Category>(); Thread.Sleep(1000); return(Json(categories, JsonRequestBehavior.AllowGet)); }