Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#HtmlHelper无法转换lambda表达式_C#_Asp.net Mvc_Lambda - Fatal编程技术网

c#HtmlHelper无法转换lambda表达式

c#HtmlHelper无法转换lambda表达式,c#,asp.net-mvc,lambda,C#,Asp.net Mvc,Lambda,我正在尝试为kendogrid创建一个自定义HtmlHelper,用于参数。 我的问题是如何重构我的viewmodel以接受一个界面htmlhelper? 这是我的htmlhelper课程 using System; using System.Web.Mvc; using Kendo.Mvc.UI; using System.Linq; using Popup.BLL.ViewModel; namespace Popup.Web.KendoHelper { public static

我正在尝试为kendogrid创建一个自定义HtmlHelper,用于参数。
我的问题是如何重构我的viewmodel以接受一个界面htmlhelper?
这是我的htmlhelper课程

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")));

        }
    }
}`
问题:c=>c.Text

MSVS:无法将lambda表达式转换为类型“string”,因为它不是委托类型

此文本本身就是字符串。编译器如何知道
T
类是否具有
Text
属性?它应该是
return helper.Kendo().Grid()
where T:class
更改为
where T:TextViewModel
,并查看它是否工作您正在使用columns.Bound(c=>c.Text)在扩展助手中传递匿名T(编译器将不知道T包含文本属性),您可以使用@th1rdey3提到的想法,或者创建一个包含属性文本的界面,我建议您这样做是可行的,谢谢。稍后我将为它创建一个接口
 .Columns(columns =>
  {
    columns.Bound(c => c).Title("Text");
  })
 .Columns(columns =>
  {
    columns.Bound(c => c).Title("Text");
  })