This is a migrated thread and some comments may be shown as answers.

GridColumnSettings issue - Loading saved GridColumnSettings causes the Grid to break

4 Answers 178 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ehtesham
Top achievements
Rank 1
Ehtesham asked on 24 Jun 2013, 05:39 PM
I have a Kendo grid generated using the ASP.NET MVC Wrapper on my cshtml page. I bind the columns using a GridColumnSettings[] prepared in the Action method for the controller and pushed to the ASP.NET page through the ViewData structure.


  .Columns(columns =>
                            {
                                columns.LoadSettings((GridColumnSettings[])ViewData["OrderReviewGrid"]);
                            })

The action methods builds the GridColumnSettings[ ] programmaticaly. After the grid is rendered for the first time, the GridColumnSettings[ ] for this particular grid are saved in the user's Profile. Any changes to the column settings on the UI e.g Column Resize, Hide, Show etc are captured and sent back on the server and updated in the saved GridColumnSettings[ ] in the user's profile.

The intention here is to be able to get the saved configuration the next time the user visit's the page.

But on the following request to the page, when the Grid is created, this time the GridColumnsSettings[] is loaded from the cached copy in the user's profile. When this is pushed to the ASP.NET page,  I get the following exception on the ASP page during the MVC Wrapper execution.

I have inspected the two structures, the default created, and the one saved and retrieved from the profile. They are exactly the same in terms of field-by-field compare.

Thanks in Advance if anyone can find what's going wrong.

Exception Details:

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.Routing.RouteValueDictionary.Add(String key, Object value) at Kendo.Mvc.UI.GridBoundColumn`2.CreateHeaderBuilderCore() at Kendo.Mvc.UI.GridColumnBase`1.CreateHeaderBuilder() at Kendo.Mvc.UI.Html.GridCellBuilderFactory.CreateHeaderCellBuilder(IGridColumn column) at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at Kendo.Mvc.UI.Html.GridRowBuilder.CreateRow() at Kendo.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow() at Kendo.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow() at Kendo.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow() at Kendo.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow() at Kendo.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow() at Kendo.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow() at Kendo.Mvc.UI.Html.GridRowBuilderDecoratorBase.CreateRow() at Kendo.Mvc.UI.Html.GridDataSectionBuilder.CreateHeader(GridRenderingData data) at Kendo.Mvc.UI.Html.GridScrollingHtmlBuilder.CreateHeader(GridRenderingData renderingData) at Kendo.Mvc.UI.Html.GridHtmlBuilder.AppendHeader(IHtmlNode container, GridRenderingData renderingData) at Kendo.Mvc.UI.Html.GridScrollingHtmlBuilder.AppendData(IHtmlNode div, GridRenderingData renderingData) at Kendo.Mvc.UI.Html.GridHtmlBuilder.CreateGrid(IDictionary`2 htmlAttributes, GridFunctionalData functionalData, GridRenderingData renderingData) at Kendo.Mvc.UI.Grid`1.WriteHtml(HtmlTextWriter writer) at Kendo.Mvc.UI.WidgetBase.ToHtmlString() at Kendo.Mvc.UI.Fluent.WidgetBuilderBase`2.ToHtmlString() at System.Web.HttpUtility.HtmlEncode(Object value) at System.Web.WebPages.WebPageBase.Write(Object value) at ASP._Page_Areas_FR_Views_OrderReview_Index_cshtml.Execute() in 

4 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 26 Jun 2013, 12:05 PM
Hello Ehtesham,


If the objects are exactly the same it should work the same way.

Consider sending a demo project which we can use to add the source code and do our best to see whats behind all this.

Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ehtesham
Top achievements
Rank 1
answered on 26 Jun 2013, 02:24 PM
Petur,
Thanks for your response.

I will build a new project to demonstrate this and if I am able to reproduce it, i'll send it to you.

Another quick question related to this. The Kendo.Mvc.UI.GridColumnSettings class is non-Serializable. Is there a reason or can it be marked as such in anupcoming build ? We have extended it for some additional
features in our grid framework and we'd like to persist it to the database as-is without a copy to another structure.

Thanks again.

Ehtesham
Teradata Canada ULC
0
Petur Subev
Telerik team
answered on 28 Jun 2013, 08:26 AM
Hello Ehtesham,

Let me know when the project is ready. 

Regarding the Serialization question - you are the first one who asks why the GridColumnSettings is not serializble and suggests to add it.

I assume it is possible to inherit the class and add the [Serializable] attribute to it.

Also do not forget to share the idea on the UserVoice page so we can consider to add it in the source.

Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ehtesham
Top achievements
Rank 1
answered on 28 Jun 2013, 04:12 PM
Thanks again Petur, I'll post it at User Voice.

As I mentioned we've derived from GridColumnSettings and marked the derived class Serializable; however without custom serialization on the derived class the object won't serialize the with exception that GridColumnSettings is not Serializable.

Thanks
Tags
Grid
Asked by
Ehtesham
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Ehtesham
Top achievements
Rank 1
Share this question
or