that\'s my function:
var errors = '@Html.Raw(Json.Encode(ViewData.ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage)))'; var errorMessage=JSON.parse(errors);