2

给定以下代码:

public static MvcHtmlString InlineEditable<T,TP>(this HtmlHelper helper, Expression<Func<T,TP>> fieldSelector)
{
    var compiledFieldSelector = fieldSelector.Compile();
    T argument = ????;
    TP value = compiledFieldSelector(argument);
    return new MvcHtmlString(GetInlineEditableMarkupInternal(helper, fieldSelector) + value);
}

我如何获得参数的值?

我试过查看 Expression.Parameters 集合,其中有一些东西,但我似乎无法找到我传入的实际 T?

我这样称呼

@Html.InlineEditable(x=>x.Property)

在 Razor 视图中。

4

1 回答 1

1

尝试这个

 public static MvcHtmlString InlineEditable<T,TP>(this HtmlHelper<T> helper, Expression<Func<T,TP>> fieldSelector)
 {
     var compiledFieldSelector = fieldSelector.Compile();
     var arg = helper.ViewData.Model;
     var value = compiledFieldSelector(arg);
     ....
 }
于 2013-04-14T18:42:38.857 回答