c# - ASP.NET,剑道用户界面,CS1660 : Cannot convert lambda expression to type 'string'

标签 c# asp.net-mvc lambda kendo-grid

帖子底部的解决方案

几天来,我一直在努力通过 Kendo.UI 网格查看我的数据, 我想我不了解如何做的一些基本概念,因为我是 aspnet 和所有这些东西的新手。

索引.cshtml:

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

家庭 Controller .cs:

...
    [HttpGet]
        public ActionResult Index()
        {
            return View();
        }

    [HttpPost]
        public JsonResult GetCards([DataSourceRequest] DataSourceRequest request)
        {
            var cards = repository.GetAll();
            var cardsvm = new CardsViewModel(cards);
            return Json(cardsvm.GetCards.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
...

项目构建没有错误,但是网页显示:

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 中的 Kendo() 用红色下划线表示

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 相关的错误,它也与 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"))
                )
    )

最佳答案

看起来您在使用 Linq 时没有将 System.Linq 嵌入到 View 中。

编辑: 您能否将断点放入 View / Controller 并确保您发送给 View 的“名称”属性是一个字符串?

关于c# - ASP.NET,剑道用户界面,CS1660 : Cannot convert lambda expression to type 'string' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27357779/

相关文章:

java - LambdaMetaFactory 中的类型

python - 使用 waiter.wait 时 AWS Lambda 作业运行两次

c# - 广播是否比特定端口的随机 SYN/ACK 扫描更快?

c# - 如何通过数据库使用日期时间选择器过滤日期

c# - 应用程序被杀死时无法接收 APNS

html - 获取具有相同名称的多个表单值( bool 大小写)

javascript - 如何获取 Asp.Net MVC 3 当前项目名称?

asp.net-mvc - ASP.NET MVC,查找模型是否发生变化

c# - 使用 Lambda 表达式从多条记录中获取最大值

c# - 如何使用 WPF 用户控件关闭父窗口