public IActionResult AddData([FromBody] IMViewModel data) { if (ModelState.IsValid) { context.AddMovie(data); return(new JsonResult(new { success = true, msg = "Success" })); } else { var errors = new StringBuilder(); foreach (ModelStateEntry modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { errors.Append(error.ErrorMessage); } } return(new JsonResult(new { success = false, msg = errors.ToString() })); } }