我有一个 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 的实例信息。如何获取对象实例并从表达式访问类实例的属性?有没有更好的方法来做到这一点?