Suppose I am writing a strongly typed HtmlHelper extension to be called from my view as:
@for (var i = 0; i < Model.Foo.Count; i++)
{
@Html.MyFormat(m => m.Foo[i].Bar);
}
Suppose I want to access other properties of Foo[i] in my helper. I know I can do this by writing code like:
@Html.MyFormat(m => m.Foo[i].Bar, m => m.Foo[i]);
But is there a less verbose way? I know how to use the System.Linq.Expressions classes to get a MethodCallExpression equivalent to 'm.Foo[i]' from 'm => m.Foo[i].Bar' but can't figure out how to actually access the object (without using .Compile to create a new lambda).
Aucun commentaire:
Enregistrer un commentaire