开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜