public class bar{
public string bar {get; set; }
}
public class foo{
public bar mybar{get; set;}
public string anotherproperty{get; set;}
}
在UI中我想这样做:
@Html.MyWhackyHelperFor(x=>x.bar)
使用:
public static MvcHtmlString MyWhackyHelperFor<TModel, TValue>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TValue>> expression){
//how can i get a the actual bar object here?
}
如何获得所引用模型的实际部分?
答案 0 :(得分:3)
您需要将表达式编译为方法,然后调用方法:
TValue val = expression.Compile()(htmlhelper.ViewData.Model);