I have an extension generic method
public static void AddError<TModel>(
this ModelStateDictionary modelState,
Expression<Func<TModel, object>> expression,
string resourceKey,
string defaultValue)
{
// How can I get a reference to TModel object from expression here?
}
I need to get the reference to TModel object from expression. This method called by the following code:
ModelState.AddError<AccountLogOnModel>(
x => x.Login, "resourceKey", "defaultValue")
x
is a parameter of the expression, you're supposed to pass an object of the type into it. (Or I'm understanding what you want to achieve wrongly.) – ProstateLogin
to use for theAddModelError(key, errorMessage)
method? UseExpressionHelper.GetExpressionText
(built in to MVC) to get the property name from a lambda expression. – Christnerlambda expression
... – Cohune