Created
September 15, 2014 10:39
-
-
Save kjeske/be87b70b7cf649527cdb to your computer and use it in GitHub Desktop.
AddModelError(Model, x=>x.PropertyName, "text")
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace System.Web.Mvc | |
{ | |
using Linq.Expressions; | |
public static class ModelStateDictionaryExtensions | |
{ | |
public static void AddModelError<TEntity, TValue>(this ModelStateDictionary modelState, TEntity model, Expression<Func<TEntity, TValue>> member, string value) | |
{ | |
var memberPath = ExpressionHelper.GetExpressionText(member); | |
modelState.AddModelError(memberPath, value); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
ModelState.AddModelError(Model, x => x.PropertyName, "Validation message")