簡體   English   中英

HTML擴展Lambda模型的兩個屬性

[英]Html Extension two properties from model with lambda

我需要調用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> 

預計兩個參數都具有相同的屬性。

我應該如何定義接收兩個屬性的方法?

更新於03-03-2015

好吧,我的擴展程序終於可以工作了

更改了我的簽名

  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)

問候

聽起來您需要為兩個屬性使用單獨的類型參數:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM