Lambda expression error using telerik MVC grid setting the DataKeys collection

StackOverflow https://stackoverflow.com/questions/22882180

  •  28-06-2023
  •  | 
  •  

Вопрос

I have the following view with a Telerik MVC Grid:

@model IEnumerable<QuoteManagement.Data.Traveler>

@(Html.Telerik().Grid(Model)
    .Name("Travelers")
    .DataKeys(k => k.DataKeys.Add(t => t.TravelerID))     //<-- error on this line
    .DataBinding(db => db.Server()
        .Delete("Delete","Traveler")
        .Update("Edit","Traveler")
        )

    .Columns(c =>
        {
            c.Command(cmd => {cmd.Edit(); cmd.Delete(); });
            c.Template(col => String.Format("{0} {1}", col.FirstName, col.LastName)).Title("Name");
            c.Bound(col => col.Birthdate);
            c.Bound(col => col.Notes);
        }))

I am getting the following compilation error: Cannot convert lambda expression to type 'Telerik.Web.Mvc.UI.IGridDataKey' because it is not a delegate type

QuoteManagement.Data.Traveler is an EF Entity type.

Это было полезно?

Решение

Fixed it - it was simple - of course:

I changed this line:

.DataKeys(k => k.DataKeys.Add(t => t.TravelerID))     

to this:

.DataKeys(k => k.Add(t => t.TravelerID))     

and now it works.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top