When I call the Create method of kendo grid its giving an exception - ''"An item with the same key has already been added". I checked that their is no any duplicate property name in the model, Only one grid on the page. Not sure what causing this error. Appreciate your help in advance.
Inner Exception :
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)<br> at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)<br> at System.Collections.Generic.CollectionExtensions.ToDictionaryFast[TKey,TValue](TValue[] array, Func`2 keySelector, IEqualityComparer`1 comparer)<br> at System.Web.Mvc.ModelBindingContext.get_PropertyMetadata()<br> at System.Web.Mvc.DefaultModelBinder.BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor)<br> at System.Web.Mvc.DefaultModelBinder.BindProperties(ControllerContext controllerContext, ModelBindingContext bindingContext)<br> at System.Web.Mvc.DefaultModelBinder.BindComplexElementalModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Object model)<br> at System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext)<br> at System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)<br> at System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor)<br> at System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor)<br> at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass3_1.<BeginInvokeAction>b__0(AsyncCallback asyncCallback, Object asyncState)
Grid :
@(Html.Kendo().Grid<PersonViewModel>(false)
.HtmlAttributes(new { @style = "height: 100%;" })
.Name("ContactGrid")
.ToolBar(toolbar => toolbar.Create())
.toolbar(tools =>
{
tools.custom().name("addnewcontact").text("add new contact".translate()).htmlattributes(new
{
id = "addnewcontact"
});
})
.Excel(e => { e.Filterable(true); e.AllPages(true); e.ForceProxy(true); e.ProxyURL("/Localized/" + nameof(LocalizedController.ExportToExcel)); })
.Editable(e =>
{
e.Enabled(true)
.DisplayDeleteConfirmation(true)
.Mode(GridEditMode.PopUp).TemplateName("PersonEditor")
.Window(w =>
{
w.Scrollable(true)
.Resizable()
.Height(245).Width(400);
});
})
.DataSource(datasource => datasource
.Custom()
.Type("aspnetmvc-ajax")
.Transport(t =>
{
t.Read(r => r.Action("Contacts_Read", "DynamicDiscountingOffer").Data("getAdditionalData").Type(HttpVerbs.Get));
t.Create(c => c.Action("Contacts_Create", "DynamicDiscountingOffer").Data("getAdditionalDataToCreateContact"));
t.Create(c => c.Action("Contacts_Create", "DynamicDiscountingOffer"));
})
.Schema(s => s
.Model(model =>
{
model.Id(p => p.VR_PersonId);
model.Field(nameof(PersonViewModel.VR_Id), typeof(int?)).DefaultValue(VrId);
model.Field(nameof(PersonViewModel.FirstName), typeof(string));
model.Field(nameof(PersonViewModel.LastName), typeof(string));
model.Field(nameof(PersonViewModel.Email), typeof(string));
})
.Errors("Errors")
.Data("Data")
.Total("Total")
)
.PageSize(10)
.ServerSorting(true)
.ServerPaging(true)
.ServerFiltering(true)
.ServerGrouping(false)
.ServerAggregates(false)
.Events(events => events.Error("error_handler"))
)
.Pageable(p => { p.Refresh(true); p.PageSizes(new int[] { 10, 20, 50, 100, 200, 2000, 5000 }); })
.Columns(columns =>
{
columns.Bound(c => c.FirstName).Width(140);
columns.Bound(c => c.LastName).Width(190);
columns.Bound(c => c.Email).Width(250);
columns.Command(command =>
{
///command.Edit().UpdateText("Submit".Translate()).Visible("editVisible").Text("Edit".Translate());
command.Custom("View").Visible("viewVisible").Text("View".Translate()).Click("showDetails");
command.Custom("Delete").Visible("deleteVisible").Text("Delete".Translate()).Click("DeleteRow");
}).Width(85).MinResizableWidth(85);
}
)
)
[DataContract] [Serializable] public class PersonViewModel : IValidatableObject { public int VR_PersonId { get; set; } [DataMember] public int VR_Id { get; set; } [DataMember] public string VendorId { get; set; } [DataMember] public Nullable<Guid> UserId { get; set; } [DataMember] public Nullable<System.DateTime> StartDate { get; set; }}
