Html扩展来自具有lambda的模型的两个属性

本文关键字:属性 两个 模型 Html lambda 扩展 | 更新日期: 2024-09-24 17:22:08

我需要调用一个从模型传递两个属性的HTML助手。问题是当我尝试这个:

 @Html.BsDropDownFor(x => x.Type.Id, x => x.Type.Descripcion, (IEnumerable<TextValue>)ViewBag.ClaseB)

头方法定义如下:

  public static MvcHtmlString BsDropDownFor<TModel>(this HtmlHelper<TModel> htmlHelper,
      Expression<Func<TModel, TProperty>> expressionValue,
      Expression<Func<TModel, TProperty>> expressionText,
      IEnumerable<TextValue> items)

如果我定义

BsDropDownFor<TModel,TProperty> 

doing在两个参数中都应具有相同的属性。

我应该如何定义接收两个属性的方法?

更新日期:2015年3月3日

好吧,我的扩展终于工作

更改了的签名

  public static MvcHtmlString BsDropDownFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper,
                                           Expression<Func<TModel, TProperty>> expression,
                                           string elementIdText,
                                           IEnumerable<TextValue> items)

expressionText是为其他扩展方法建立的,在视图上称为

@Html.BsDropDownFor(x => x.Type.Id, Html.ModelPropertyTagId( x => x.Type.Descripcion), (IEnumerable<TextValue>)ViewBag.ClaseB)

关于

Html扩展来自具有lambda的模型的两个属性

听起来您需要两个属性的独立类型参数:

public static MvcHtmlString BsDropDownFor<TModel, TValue, TText>(
       this HtmlHelper<TModel> htmlHelper,
       Expression<Func<TModel, TValue>> expressionValue,
       Expression<Func<TModel, TText>> expressionText,
       IEnumerable<TextValue> items)
{
   ...
}