SOLUZIONE IN FONDO POSTASP.NET, Kendo UI, CS1660: Impossibile convertire espressione lambda al tipo 'stringa'
ho lottato per vedere i miei dati attraverso una griglia Kendo.UI per pochi giorni, Immagino di non riuscire a capire un concetto di base su come farlo da quando sono nuovo su Aspnet e tutto questo genere di cose.
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);
}
...
progetto si basa senza errori, ma la pagina web dice:
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: Come suggerito, ho provato ponendo punti di interruzione e calcolato che il programma si blocca subito dopo la fine dell'Indice (inclusa l'azione Indice homeControllers c ode);
EDIT2: @clement il Kendo() in layout.cshtml è sottolineata in rosso, dicendo
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 Credo che sia un Visual Studio bug legato, che è anche collegato a IntelliSense non funziona correttamente in file cshtml. I miei colleghi dicono che hanno questo nei loro progetti, ma lo ignorano e funziona.
SOLUZIONE: Così funziona se si cambia Index.cshtml a:
@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"))
)
)
Si consiglia di scambiare System.Linq su System.Data.Entity –
Sto utilizzando NHibernate in questo progetto – evictednoise