HtmlHelper访问父对象

时间:2015-04-03 19:25:48

标签: asp.net-mvc linq reflection html-helper expression-trees

假设我正在编写一个强类型的HtmlHelper扩展,从我的视图中调用:

@for (var i = 0; i < Model.Foo.Count; i++)
{
    @Html.MyFormat(m => m.Foo[i].Bar);
}

假设我想在我的助手中访问Foo [i]的其他属性。我知道我可以通过编写代码来实现这一点:

    @Html.MyFormat(m => m.Foo[i].Bar, m => m.Foo[i]);

但是有一种不那么冗长的方式吗?我知道如何使用System.Linq.Expressions类来获得一个等于&#39; m.Foo [i]&#39;的MethodCallExpression。 from&#39; m =&gt; m.Foo [I]标尺示&#39;但无法弄清楚如何实际访问对象(不使用.Compile创建新的lambda)。

0 个答案:

没有答案
相关问题