The model item passed into the dictionary is of type 'System.Double', but this dictionary requires a model item of type 'System.String'.The model item passed into the dictionary is of type 'System.Double', but this dictionary requires a model item of type 'System.String'.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Double', but this dictionary requires a model item of type 'System.String'.Source Error: Line 53: Line 54: <script id="template" type="text/kendo-tmpl">Line 55: @(Html.Kendo().Grid<Toolbox.Web.Models.RebateAverageCostViewModel>()Line 56: .Name("grid_#=ID#")Line 57: .Columns(columns =>Source File: c:\Data\Source\Work\2\Wilco\Toolbox\Main\Toolbox.Web\Views\RebateAverageCosts\Index.cshtml Line: 55 Stack Trace: [InvalidOperationException: The model item passed into the dictionary is of type 'System.Double', but this dictionary requires a model item of type 'System.String'.] System.Web.Mvc.ViewDataDictionary`1.SetModel(Object value) +584415 System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary) +371 System.Web.Mvc.WebViewPage`1.SetViewData(ViewDataDictionary viewData) +48 System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +98 System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115 System.Web.Mvc.Html.TemplateHelpers.ExecuteTemplate(HtmlHelper html, ViewDataDictionary viewData, String templateName, DataBoundControlMode mode, GetViewNamesDelegate getViewNames, GetDefaultActionsDelegate getDefaultActions) +579 System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData, ExecuteTemplateDelegate executeTemplate) +1002 System.Web.Mvc.Html.TemplateHelpers.TemplateHelper(HtmlHelper html, ModelMetadata metadata, String htmlFieldName, String templateName, DataBoundControlMode mode, Object additionalViewData) +66 System.Web.Mvc.Html.TemplateHelpers.TemplateFor(HtmlHelper`1 html, Expression`1 expression, String templateName, String htmlFieldName, DataBoundControlMode mode, Object additionalViewData, TemplateHelperDelegate templateHelper) +117 System.Web.Mvc.Html.TemplateHelpers.TemplateFor(HtmlHelper`1 html, Expression`1 expression, String templateName, String htmlFieldName, DataBoundControlMode mode, Object additionalViewData) +104 System.Web.Mvc.Html.EditorExtensions.EditorFor(HtmlHelper`1 html, Expression`1 expression, Object additionalViewData) +62 Kendo.Mvc.UI.Html.GridEditorForCellBuilder`2.AppendEditorFor(HtmlHelper`1 htmlHelper, IHtmlNode container) +62 Kendo.Mvc.UI.Html.GridEditorForCellBuilder`2.AppendEditor(IHtmlNode container, HtmlHelper`1 htmlHelper) +52.... snip .....@(Html.Kendo().Grid<Toolbox.Web.Models.RebateAverageCostItemViewModel>() .Name("grid") .DataSource(dataSource => dataSource // Configure the grid data source .Ajax() // Specify that ajax binding is used //.Batch(true) // Enable batch updates .Model(model => { model.Id(item => item.ID); // Specify the property which is the unique identifier of the model model.Field(item => item.ID).Editable(false); // Make the property not editable }) .Read(read => read.Action("RebateAverageCostItems_Read", "RebateAverageCosts")) // Set the action method which will return the data in JSON format ) .Columns(columns => { columns.Bound(c => c.ID).Width(10); columns.Bound(c => c.ItemNo).Width(100); columns.Bound(c => c.ProductDescription).Width(200); columns.Bound(c => c.ProductGroup).Width(100); columns.Bound(c => c.PackSize).Width(100); columns.Bound(c => c.Supplier).Width(100); columns.Bound(c => c.PriceUOM).Width(100); }) //.Editable(editable => editable.Mode(GridEditMode.InCell)) // Use in-cell editing mode .Pageable() // Enable paging .Sortable() // Enable sorting .Filterable() // Endable filtering .ClientDetailTemplateId("template") .Events(events => events.DataBound("dataBound")))<script id="template" type="text/kendo-tmpl"> @(Html.Kendo().Grid<Toolbox.Web.Models.RebateAverageCostViewModel>() .Name("grid_#=ID#") .Columns(columns => { columns.Bound(c => c.ID).Width(10); columns.Bound(c => c.BeginDate); columns.Bound(c => c.EndDate); columns.Bound(c => c.NetCostAfterRebate); }) .DataSource(dataSource => dataSource .Ajax() // Specify that ajax binding is used .Batch(true) // Enable batch updates .Model(model => { model.Id(item => item.ID); // Specify the property which is the unique identifier of the model model.Field(item => item.ID).Editable(false); // Make the property not editable }) .Read(read => read.Action("RebateAverageCosts_Read", "RebateAverageCosts", new { rebateAverageCostItemId = "#=ID#" })) )// Note if I comment out this line, it works in read only mode.... .Editable(editable => editable.Mode(GridEditMode.InCell)) // Use in-cell editing mode .Pageable() // Enable paging .Sortable() // Enable sorting .ToClientTemplate() )</script>I've done some digging myself on my side by logging the grid's Edit event, and I can verify that the event is not being fired when the first cell is highlighted, but it is being fired when that last tab occurs (when the second column becomes a text field).
Does there happen to be a simple way of resolving this issue that I'm overlooking?
Thanks.
01.public static CustomGridFor<TProperty> KendoGrid<TModel, TProperty>(02. Expression<Func<TModel, IEnumerable<TProperty>>> expression,03. string defaultProperty,04. string createAction,05. string readAction,06. string updateAction,07. string controller,08. string errorHandler) where TProperty : class09.{10. var dataSource = expression.Compile().Invoke(htmlHelper.ViewData.Model);11. var gridColumnSettings = GridBuilderExtensions.CreateGridColumnSettings<TProperty>() as List<GridColumnSettings>;12. if (gridColumnSettings != null)13. {14. gridColumnSettings.Add(new GridCommandColumnSettings { Commands = { new GridEditActionCommand(), }, });15. }16. 17. var gridBuilder = new this.Grid(dataSource)18. .Name("GridName")19. .Columns(c => c.LoadSettings(gridColumnSettings))20. .DataSource(source => source21. .Ajax() 22. .PageSize(50)23. .Model(model => model.Id(defaultProperty))24. .Destroy(d => d.Action(destroyAction, controller))25. .Read(r => r.Action(readAction, controller))26. .Update(u => u.Action(updateAction, controller))27. .Batch(true)28. .Events(e => e.Error(errorHandler)))29. .ToolBar(a => a.Create().Text("New"))30. .Editable(editable => editable.Mode(GridEditMode.InLine));31. 32. return gridBuilder;33.}01....02.columns.Bound(p => p.Category).ClientTemplate("#=Category.CategoryName#").Width(160);03....04..Model(model =>05.{06. model.Id(p => p.ProductID);07. model.Field(p => p.ProductID).Editable(false);08.})09....1....2..DataSource(source => source.Ajax()3. .Model(model =>4. {5. model.Id(p => p.ProductID);6. model.Field(p => p.ProductID).Editable(false);7. })8....1..Columns(c => c.LoadSettings(new IEnumerable<GridColumnSettings>()))Hi,
I’m working with a Kendo Grid using MVC4 with Razor’s syntax.
I need to be able to customize column’s order and displaying option in order to save user’s preference.
To achieve that, I tried to use a tab of GridColumnSettings and load it in the View using the LoadSettings method of the columns property.
I have a few issues with that:
- Even if the column order can be set dynamically with this method, I don’t understand how to use ClientTemplate or Template attribute of the GridColumnSettings object.
- By using this loading system I have two Gird's options who don’t work anymore: line and column are not selectable and the groupable option seems to not work too.
Thanks for your help.