How to get this expression value model => model.Name?
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.Mod开发者_如何学运维el);//problem that is value is null
}
(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.
Use ModelMetadata.FromLambdaExpression Method and then its property Model
精彩评论