This question is locked. New answers and comments are not allowed.
ASP.Net MVC 2012 Q1
I have a .aspx page that contains a Telerik Grid. Within the details view of my grid, I have a TabStrip. Within each tab there is a Telerik Grid. Within each Grid I have a ForeignKey column. In the first Grid the ForeignKey column points to ViewData["AddressTypes"]. In the second Grid the ForeignKey column points to ViewData["EmailAddressTypes"]. Both of these lists (i.e. ViewData["AddressTypes"] and ViewData["EmailAddressTypes"]) contain the same elements and therefore have the same Ids. When I run the application I get the following error and stack trace. Further below is my markup.
NOTE: This error appears to be the ForeignKeyColumns using same lists in conjunction with having Edit and Delete Commands. If I comment out either the foreignKey columns or the command columns then I get no error.
An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Web.Mvc.ViewDataDictionary.Add(String key, Object value)
at Telerik.Web.Mvc.UI.GridForeignKeyColumn`2.AppendSelectList(IDictionary`2 viewData, Object dataItem) in f:\114\Griffin\Trunk Full\Sources\Source\Telerik.Web.Mvc\UI\Grid\Columns\GridForeignKeyColumn.cs:line 96
Thanks,
I have a .aspx page that contains a Telerik Grid. Within the details view of my grid, I have a TabStrip. Within each tab there is a Telerik Grid. Within each Grid I have a ForeignKey column. In the first Grid the ForeignKey column points to ViewData["AddressTypes"]. In the second Grid the ForeignKey column points to ViewData["EmailAddressTypes"]. Both of these lists (i.e. ViewData["AddressTypes"] and ViewData["EmailAddressTypes"]) contain the same elements and therefore have the same Ids. When I run the application I get the following error and stack trace. Further below is my markup.
NOTE: This error appears to be the ForeignKeyColumns using same lists in conjunction with having Edit and Delete Commands. If I comment out either the foreignKey columns or the command columns then I get no error.
An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Web.Mvc.ViewDataDictionary.Add(String key, Object value)
at Telerik.Web.Mvc.UI.GridForeignKeyColumn`2.AppendSelectList(IDictionary`2 viewData, Object dataItem) in f:\114\Griffin\Trunk Full\Sources\Source\Telerik.Web.Mvc\UI\Grid\Columns\GridForeignKeyColumn.cs:line 96
.DetailView(details2 => details2.ClientTemplate( Html.Telerik().TabStrip() .Name("TabStrip_<#= Id #>") .SelectedIndex(0) .Items(items2 => { items2.Add().Text("Addresses").Content ( Html.Telerik().Grid<AddressModel>().Name("UserAddress_<#= Id #>") .DataKeys(keys => { keys.Add(a => a.Id).RouteKey("addressId"); keys.Add(a => a.OwnerId).RouteKey("addressOwnerId"); }) .Columns(columns => { columns.ForeignKey(a => a.TypeId, (IEnumerable)ViewData["AddressTypes"], "Id", "Name").Width(100); columns.Bound(a => a.AddressLine1).Width(200); columns.Bound(a => a.AddressLine2).Width(200); columns.Bound(a => a.City).Width(120); columns.ForeignKey(a => a.StateId, (IEnumerable)ViewData["States"], "Id", "Name").Width(100); columns.Bound(a => a.ZipCode).Width(100); columns.Command(commands => { commands.Edit(); commands.Delete(); }).Width(100); }) .DataBinding(dataBinding => dataBinding.Ajax() .Select("AddressAjax", "Group", new { organizationalUnitId = "<#= Id #>" }) .Insert("InsertAddress", "Group") .Update("SaveAddress", "Group") .Delete("DeleteAddress", "Group") ) .Pageable() .Sortable() .Filterable() .ToHtmlString() ); items2.Add().Text("Email").Content ( Html.Telerik().Grid<EmailModel>().Name("UserEmailAddress_<#= Id #>") .DataKeys(keys => { keys.Add(e => e.Id).RouteKey("emailId"); keys.Add(e => e.OwnerId).RouteKey("ownerId"); }) .Columns(columns => { columns.Bound(e => e.EmailAddress).Width(200); columns.ForeignKey(e => e.TypeId, (IEnumerable)ViewData["EmailAddressTypes"], "Id", "Name").Width(100); columns.Command(commands => { commands.Edit(); commands.Delete(); }).Width(100); }) .DataBinding(dataBinding => dataBinding.Ajax() .Select("EmailAddressAjax", "Group", new { organizationalUnitId = "<#= Id #>" }) .Insert("InsertEmailAddress", "Group") .Update("SaveEmailAddress", "Group") .Delete("DeleteEmailAddress", "Group") ) .Pageable() .Sortable() .Filterable() .ToHtmlString() ); }) .ToHtmlString() ))Thanks,