public IActionResult CreateAjax(TestCategory testCategory) { if (ModelState.IsValid) { if (_TestCategoryManager.IsExists(testCategory)) { return(Json(new { status = false, message = $"{nameof(TestCategory.Name)} Already exists" })); } else { int uId = User.Id(); testCategory.CreatorId = uId; _TestCategoryManager.Add(testCategory); return(Json(new { status = true, message = "Successfully created, the list will refresh again in 1 second." })); } } else { string errors = ""; foreach (var modelState in ModelState.Values) { foreach (var error in modelState.Errors) { if (errors.Length > 0) { errors += "\r\n"; } errors += error.ErrorMessage; } } return(Json(new { status = false, message = errors })); } }