Reputation: 6431
I am trying to get below expression value by compiling and invoking but i get some errors and no success till now.
public static void TextEditorFor<TModel, TProperty>(this System.Web.Mvc.HtmlHelper<TModel> html, Expression<Func<TModel, TProperty>> expression)
{
var value = expression.Compile().Invoke(html.ViewData.Model);//problem that is value is null
}
Upvotes: 2
Views: 1262
Reputation: 39501
Use ModelMetadata.FromLambdaExpression Method and then its property Model
Upvotes: 0
Reputation: 1062975
(applies to the original question)
Given the signature, you should just need:
return Convert.ToString(
expression.Compile().Invoke(modelInstance)
);
You can also do this by inspection of the expression if absolutely needed.
Upvotes: 2