C# ASP.NET,Kendo UI,CS1660:无法将lambda表达式转换为类型';字符串';
在柱子底部的解决方案 几天来,我一直在努力通过Kendo.UI网格查看数据, 我猜我没有理解一些关于如何做的基本概念,因为我是aspnet和所有这类东西的新手 Index.cshtml:C# ASP.NET,Kendo UI,CS1660:无法将lambda表达式转换为类型';字符串';,c#,asp.net-mvc,lambda,kendo-grid,C#,Asp.net Mvc,Lambda,Kendo Grid,在柱子底部的解决方案 几天来,我一直在努力通过Kendo.UI网格查看数据, 我猜我没有理解一些关于如何做的基本概念,因为我是aspnet和所有这类东西的新手 Index.cshtml: @using Kendo.Mvc.UI @using System.Linq; @(Html.Kendo().Grid<CardsDemo.Models.CardsViewModel>() .Name("Grid") .Columns(columns =>
@using Kendo.Mvc.UI
@using System.Linq;
@(Html.Kendo().Grid<CardsDemo.Models.CardsViewModel>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.Name).Title("Card ID").Width(130);
columns.Bound(p => p.State).Title("State").Width(130);
columns.Bound(p => p.ExpirationDate).Title("Expiration Date").Width(130);
})
.Pageable()
.Sortable()
.Scrollable(scr => scr.Height(430))
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.ServerOperation(false)
.Read(read => read.Action("GetCards", "Home"))
).Render()
)
项目构建没有错误,但网页上显示:
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1660: Cannot convert lambda expression to type 'string' because it is not a delegate type
Source Error:
Line 8: .Columns(columns =>
Line 9: {
Line 10: columns.Bound(p => p.Name).Title("Card ID").Width(130);
Line 11: columns.Bound(p => p.State).Title("State").Width(130);
Line 12: columns.Bound(p => p.ExpirationDate).Title("Expiration Date").Width(130);
Source File: c:\Users\me\Documents\Visual Studio 2013\Projects\CardsDemo\Views\Home\Index.cshtml Line: 10
编辑:正如建议的那样,我尝试放置断点,并认为程序在索引结束后立即崩溃(包括homeControllers索引操作代码)
EDIT2:@clement layout.cshtml中的剑道()以红色下划线,表示
Error 3 'System.Web.WebPages.Html.HtmlHelper' does not contain a definition for 'Kendo' and no extension method 'Kendo' accepting a first argument of type 'System.Web.WebPages.Html.HtmlHelper' could be found (are you missing a using directive or an assembly reference?) c:\Users\me\Documents\Visual Studio 2013\Projects\CardsDemo\Views\Home\Index.cshtml 3 12 CardsDemo
但我认为这是一个与Visual Studio相关的bug,它也与IntelliSense在cshtml文件中无法正常工作有关。
我的同事们说,他们的项目中也有这种情况,但他们只是忽略了它,它就起作用了
解决方案:如果将Index.cshtml更改为:
@model ICollection<CardsDemo.Models.CardViewModel>
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.Name);
columns.Bound(p => p.State);
columns.Bound(p => p.ExpirationDate);
})
.Pageable()
.Sortable()
.Scrollable(scr => scr.Height(430))
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Read(read => read.Action("GetCards", "Home"))
)
)
@model i采集
@(Html.Kendo().Grid(模型)
.名称(“网格”)
.列(列=>
{
columns.Bound(p=>p.Name);
columns.Bound(p=>p.State);
columns.Bound(p=>p.ExpirationDate);
})
.Pageable()
.Sortable()
.可滚动(scr=>scr.高度(430))
.可过滤()
.DataSource(DataSource=>DataSource
.Ajax()
.页面大小(20)
.Read(Read=>Read.Action(“GetCards”,“Home”))
)
)
看起来您使用Linq时没有将System.Linq嵌入到视图中
编辑:
能否将断点放入视图/控制器,并确保发送到视图的“Name”属性是字符串?“@using System.Linq;”无论我是否拥有它,都不会改变任何内容:(@mattytommo抱歉,我没有看到这个我已经更新了问题(请参见问题末尾的编辑)感谢您愿意帮助“Name”是一个整数,尝试将其更改为字符串,但没有帮助。始终是相同的错误?没有异常?您能否在全局asax中生成应用程序错误以捕获异常(如果有异常)?您可能希望将System.Linq交换为System.Data.EntityI在该项目中使用NHibernate
@model ICollection<CardsDemo.Models.CardViewModel>
@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.Name);
columns.Bound(p => p.State);
columns.Bound(p => p.ExpirationDate);
})
.Pageable()
.Sortable()
.Scrollable(scr => scr.Height(430))
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Read(read => read.Action("GetCards", "Home"))
)
)