ASP.NET, Kendo UI, CS1660: Cannot convert lambda expression to enter "string"

SOLUTION ON POST NUMBER

I struggled to view my data through the Kendo.UI grid for several days, I think I don’t understand the basic concept of how to do this, since I am new to aspnet and all similar materials.

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); } ... 

The project is built without errors, but the web page says:

 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: As suggested, I tried to set breakpoints and realized that the program crashed immediately after the index ended (including the action code of the HomeControllers Index);

EDIT2: @clement Kendo () in layout.cshtml is underlined in red, saying

 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 I believe this is a Visual Studio-related error, which is also due to the fact that IntelliSense is not working properly in cshtml files. My colleagues say that they also have this in their projects, but they just ignore it and it works.

SOLUTION: This works if you change Index.cshtml to:

 @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")) ) ) 
+5
source share
1 answer

it looks like you are using Linq without inserting System.Linq into the view.

EDIT: Can you put a breakpoint in view / controller and make sure that the Name property that you submit to view is a string?

0
source

Source: https://habr.com/ru/post/1208575/


All Articles