Skip to content

Instantly share code, notes, and snippets.

@rschiefer
Created June 4, 2018 17:20
Show Gist options
  • Save rschiefer/ee266e9ab38ca5ee279134e14c268a41 to your computer and use it in GitHub Desktop.
Save rschiefer/ee266e9ab38ca5ee279134e14c268a41 to your computer and use it in GitHub Desktop.
protected JsonResult RemoteJsonResponseForProperty(string property = null)
{
object response;
if (string.IsNullOrWhiteSpace(property))
{
property = System.Web.HttpContext.Current.Request.QueryString.Keys[0];
}
if (ModelState.ContainsKey(property) && ModelState[property].Errors.Any())
{
response = string.Join(". ", ModelState[property].Errors.Select(e => e.ErrorMessage));
}
else
{
response = true;
}
return Json(response, JsonRequestBehavior.AllowGet);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment