我有一个 HTML 帮助器,我需要向其传递一个对象。这个对象是一个类,它具有一些我需要在帮助器中访问的属性。该对象的实际基类是泛型类型,因此我决定使用 Linq 表达式并将对象传递给它。
这是方法签名:
public static MvcHtmlString PartyDetailsField<TModel, TProperty>(this HtmlHelper<TModel> helper, string controlLabelText, Expression<Func<TModel, TProperty>> expression, IEnumerable<IDetailsConfiguration> configuation, string width = "")
这是我使用该控件的方式:
@Html.PartyDetailsField("Identifiers", m => m.Person, Model.IdentifierConfiguration, "186px")
我需要来自 m.Person 的实例信息。如何从表达式中获取对象实例并访问类实例的属性?有更好的方法吗?
I have an HTML helper that I need to pass an Object to. This Object is a class that has some Properties on it that I would need to access in the helper. The actual base class of this object is a generic type so I decided that I would use a Linq expression and pass it the object.
Here is the method signature:
public static MvcHtmlString PartyDetailsField<TModel, TProperty>(this HtmlHelper<TModel> helper, string controlLabelText, Expression<Func<TModel, TProperty>> expression, IEnumerable<IDetailsConfiguration> configuation, string width = "")
Here is how I use the control:
@Html.PartyDetailsField("Identifiers", m => m.Person, Model.IdentifierConfiguration, "186px")
I need the instance information from m.Person. How can I get the object instance and access the properties of the class instance from the expression? Is there a better way of doing this?
发布评论
评论(1)
建议阅读这篇文章http://blogs.msdn.com/b/csharpfaq/archive/2010/03/11/how-can-i-get-objects-and-property-values-from-expression-trees。 ASPX
suggest reading this post http://blogs.msdn.com/b/csharpfaq/archive/2010/03/11/how-can-i-get-objects-and-property-values-from-expression-trees.aspx