LÖSUNG AM ENDE POST eingebenASP.NET, Kendo UI, CS1660: Kann nicht Lambda-Ausdruck konvertieren ‚string‘
Ich habe zu kämpfen meine Daten durch ein Kendo.UI Raster für ein paar Tage zu sehen, Ich schätze, ich verstehe nicht, ein grundlegendes Konzept zu verstehen, wie es zu tun, da ich neu in Aspnet und all diese Art von Sachen bin.
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);
}
...
Projekt ohne Fehler baut, aber die Webseite sagt:
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
EDIT: Wie bereits angedeutet, habe ich versucht, Breakpoints setzen und festgestellt haben, dass das Programm direkt nach dem Ende des Index abstürzt (inkl. homeControllers Index Aktion c Ode);
EDIT2: @clement die Kendo() in layout.cshtml ist rot unterstrichen, sagen
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
Tho Ich glaube, es ist ein Visual Studio ist Bug verwandt, die auch IntelliSense angeschlossen nicht richtig funktioniert in cshtml Dateien. Meine Kollegen sagen, sie haben dies auch in ihren Projekten, aber sie ignorieren es einfach und es funktioniert.
LÖSUNG: Also es funktioniert, wenn Sie Index.cshtml ändern:
@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"))
)
)
Möglicherweise möchten Sie System.Linq zu System.Data.Entity –
tauschen Ich verwende NHibernate in diesem Projekt – evictednoise