2015-03-02 38 views
2

我需要调用一个HTML助手来传递模型中的两个属性。问题是,当我试试这个:Html扩展与lambda模型的两个属性

@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> 

做,预计在两个参数相同的属性。

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

更新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) 

关于

回答

3

这听起来像你需要两个属性不同的类型参数:

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

我的预期发现了一些如何@Html ...(新[] {X => x.Type.Id,X => X .Type.Description},..其他参数),谢谢JLRishe – 2015-03-03 21:29:25

+0

你是对的,重构后代码中加入了两个类型参数和HtmlProperties,谢谢JLRishe – 2017-02-20 04:59:26