An item with the same key has already been added.

2 posts, 0 answers
  1. Gavin
    Gavin avatar
    3 posts
    Member since:
    Jun 2016

    Posted 22 Jun Link to this post

    Hi, I have seen this error in a number of threads on the forum, none of which seem to be caused by the same thing as I am trying. 

     

    All it amounts to is using the same 'Id' column in the expressions for both a custom command routing value and the datasource server() model id mapping. I dont really understand why using the id in these two places should cause this problem?

     

                @(Html.Kendo().Grid(Model.DetailRecords).Name("MyGrid")
                    .Columns(columns =>
                    {
                        columns.Command(commands => commands.Custom("View").Action("Index", "Detail")
                            .DataRouteValues(rv => rv.Add(m => m.Id)));
                        columns.Bound(m => m.Heading);
                    })
                    .DataSource(ds => ds.Server().Model(model => model.Id(m => m.Id)))
                )

    If this is a bug, is there a work around I can use?

     

    Thanks,

    Gavin

  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1793 posts

    Posted 24 Jun Link to this post

    Hello Gavin,

    The Id field from the model will be automatically passed as parameter for the custom command, so that is why you are receiving the error message. You can safely remove that field from the DataRouteValues and you will still be to retrieve it.

    Hope this helps.


    Regards,
    Konstantin Dikov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top