c#HtmlHelper不能转换lambda表达式

问题描述:

我正在尝试为参数使用kendogrid创建一个自定义的HtmlHelper。
我的问题是如何重塑我的viewmodel接受一个接口的htmlhelper?
这里是我HtmlHelper类c#HtmlHelper不能转换lambda表达式

using System; 
using System.Web.Mvc; 
using Kendo.Mvc.UI; 
using System.Linq; 
using Popup.BLL.ViewModel; 

namespace Popup.Web.KendoHelper 
{ 
    public static class PickListHelper 
    { 
     public static Kendo.Mvc.UI.Fluent.GridBuilder<T> PickList<T>(this HtmlHelper helper, string gridName, string gridClass, int gridHeight) 
      where T : class 
     { 
      return helper.Kendo().Grid<T>() 
      .Name(gridName) 
        .Columns(columns => 
        { 
         columns.Bound(c => c.Text).Title("Associated"); 
        }) 
      .HtmlAttributes(new { @class = gridClass, style = "height: " + gridHeight + "px;" }) 
      .Scrollable() 
      .Sortable() 
      .Selectable(selectable => selectable 
       .Mode(GridSelectionMode.Multiple)) 
      .Events(events => events.Change("onSelectAssociatedGridElements")) 
      .DataSource(datasource => datasource.Ajax().Read(read => read.Data("getAssociatedGridDataSource"))); 

     } 
    } 
}` 

和我ViewModel类

public class TextViewModel 
    { 
     public int Id { get; set; } 
     public string Text { get; set; } 
    } 

问题:C => c.Text
MSVS:无法转换lambda表达式到类型 '串',因为它是不代表类型

+1

此文本本身就是字符串。 –

+0

编译器如何知道'T'类是否具有'Text'属性?它应该是'return helper.Kendo()。Grid ()' –

+1

将'where T:class'更改为'where T:TextViewModel'并查看它是否有效 – th1rdey3

.Columns(columns => 
    { 
    columns.Bound(c => c).Title("Text"); 
    })