This is a migrated thread and some comments may be shown as answers.
"The DataKeys collection is empty. Please specify a data key."
5 Answers 207 Views
This is a migrated thread and some comments may be shown as answers.
figueiredorj
Top achievements
Rank 1
figueiredorj asked on 10 Jun 2012, 07:27 PM
Hi. 
I am having an used (I think) issue on grid.
"The DataKeys collection is empty. Please specify a data key."

For telerik mvc extensions it is documented issue but I don't find how to fix it with kendo MVC
My grid:
@(Html.Kendo().Grid(Model)
 
    .Name("Grid")
    .Columns(columns =>
                 {
                      
                     columns.Bound(p => p.ClientSetName).Width(100).Title("Client");
                     columns.Bound(p => p.IMEI).Width(100).Title("IMEI");
                     columns.Bound(p => p.Active).Width(200).Title("Active");
                     columns.Bound(p => p.Inserted).Title("Inserted");
                     columns.Command(commands =>
                     {
                         commands.Edit();
                     }).Width(200);
                 })
 
        .Groupable()
        .Pageable()
        .Sortable()
        .Scrollable()
        .Filterable()
        .DataSource(dataSource => dataSource
            .Ajax()
            .Read(read => read.Action("_Index", "Kit"))
        )
)
and my ViewModel:
public class KitViewModel
{
    [ScaffoldColumn(true)]
    [UIHint("Kit")]
    public Guid Id { get; set; }
 
    [StringLength(15), Required]
    [DisplayName("IMEI")]
    public string IMEI { get; set; }
 
    [ReadOnly(true)]
    [DisplayName("Active")]
    public bool Active { get; set; }
 
    [DisplayFormat(DataFormatString = "{0:dd MM yyyy}")]
    [DataType(DataType.DateTime), Required]
    [ReadOnly(true)]
    [DisplayName("Inserted")]
    public DateTime Inserted { get; set; }
 
    [DisplayFormat(DataFormatString = "{0:dd MM yyyy}")]
    [DataType(DataType.DateTime), Required]
    [ReadOnly(true)]
    [DisplayName("Updated")]
    public DateTime Updated { get; set; }
 
    [UIHint("Client")]
    [ScaffoldColumn(true)]
    public Guid ClientId { get; set; }
 
    [DisplayName("Client")]
    public string ClientSetName { get; set; }
}
How can I fix this in kendo mvc?
Thanks

5 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 11 Jun 2012, 07:10 AM
Hello,

The error is raised due to the fact that no id field is specified. This should be set through DataSource's configuration, similar to the following:

.DataSource(dataSource => dataSource       
        .Model(model => model.Id(p => p.Id))
        //....
)

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
figueiredorj
Top achievements
Rank 1
answered on 11 Jun 2012, 10:32 AM
Hi Rosen.
Thanks for answering.

However unless I am using an outdated dll for mvc kendo I do not have access Model in Datasource.
Is there an updated dll other than the one in msi installer?

Thanks
0
Rosen
Telerik team
answered on 11 Jun 2012, 12:31 PM
Hello,

Could you please provide a small sample in which the behavior you are experiencing can be observed locally. Meanwhile, you may refer to this help article which describes how to configure Grid widget for Ajax editing.

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
figueiredorj
Top achievements
Rank 1
answered on 11 Jun 2012, 12:54 PM
Hi Again.
This is my grid code:
@(Html.Kendo().Grid( Model)
    .Name("Grid")
    .Columns(columns =>
                 {
                      
                     columns.Bound(p => p.ClientSetName).Width(100).Title("Client");
                     columns.Bound(p => p.Active).Width(200).Title("Active");
                     columns.Bound(p => p.Inserted).Title("Inserted");
                   })
 
        .Groupable()
        .Pageable()
        .Sortable()
        .Scrollable()
        .Filterable()
        .DataSource(dataSource => dataSource
             
            .Ajax()
            .Read(read => read.Action("_Index", "Kit"))
        )
)
As you mentioned I was expecting do add it on datasource... it would seem something like 

.DataSource(dataSource => dataSource
    .Model(model => model.Id(p => p.Id))
    .Ajax()
    .Read(read => read.Action("_Index", "Kit"))
)
However I am unable to add Model as there is no definition for it.

I am using it with a MVC4 project. Don't know if it matters. But I have tested on "Examples" of Kendo MVC to see if Model was there and behavior is the same.
0
Accepted
Rosen
Telerik team
answered on 11 Jun 2012, 01:02 PM
Hi,

You should add it after the Ajax setting (as described in the article I have mentioned in my previous message):

.DataSource(dataSource => dataSource
    .Ajax()
    .Model(model => model.Id(p => p.Id))
    .Read(read => read.Action("_Index", "Kit"))

The Ajax setting is the "entry point" for this DataSource option.

Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
figueiredorj
Top achievements
Rank 1
Answers by
Rosen
Telerik team
figueiredorj
Top achievements
Rank 1
Share this question
or