发布底部的解决方案
我一直在努力通过Kendo.UI网格查看我的数据几天, 因为我是aspnet的新手以及所有这些东西,所以我无法理解一些关于如何做的基本概念。
Index.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()
)
HomeController.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 Index操作代码);
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"))
)
)
答案 0 :(得分:0)
看起来您在没有将 System.Linq 嵌入视图的情况下使用Linq。
编辑: 你能把断点放到视图/控制器中,并确保&#34;名称&#34;您发送到视图的属性是字符串?