Skip to content

Instantly share code, notes, and snippets.

@timiles
Created May 30, 2012 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timiles/2835527 to your computer and use it in GitHub Desktop.
Save timiles/2835527 to your computer and use it in GitHub Desktop.
eg ModelState.Try("model.Email", () => user.ChangeEmail(newEmail));
// credit: @mcintyre321
public static class ModelStateDictionaryExtensions
{
public static bool Try(this ModelStateDictionary ms, string key, Action action)
{
try
{
action();
return true;
}
catch (Exception ex)
{
ms.AddModelError(key, ex);
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment