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

Allow inline/cell editing without concrete model

3 Answers 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 02 Apr 2019, 02:13 PM

I'm looking at using the grid in a generic way with the help of a custom Html Helper. 

Is it possible to pass my model to the grid like so @Html.Kendo().Grid(Model) (not like Grid<SomeClass>()) within a partial view without declaring a concrete model such as @model IEnumerable<SomeClass>? Model would be a generic such as IEnumerable<object>, dynamic or find a way to cast it as it's native type in some way.

3 Answers, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 04 Apr 2019, 08:16 AM
Hi Christian,

Binding the Kendo UI Grid to a dynamic object is a plausible solution. The essential part would be to identify the model's ID of the data source in order for the CRUD operations to be working as expected. We have created a sample project and uploaded it to our public GitHub repository which demonstrates how this functionality can be achieved. 

https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/grid/grid-bind-to-collection-dynamic

The files of interest a the Index.cshtml located ~Views/Home folder and the Home controller located in the Controllers folder. Take a look at the project and let me know in case additional assistance is required.


Kind regards,
Tsvetomir
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Christian
Top achievements
Rank 1
answered on 04 Apr 2019, 11:59 AM
Thanks for responding. I had previously looked into that project but came to the conclusion that only the PopUp mode was supported using a dynamic. Other modes would end with a NotSupportException: Templates require accessible properties... I would really prefer inline.
0
Tsvetomir
Telerik team
answered on 08 Apr 2019, 10:14 AM
Hi Christian,

I have reworked the same project to be using the InLine editing mode of the Kendo UI Grid. I did encounter the same issue you have described. However, I did investigate the stack trace and it appears that this exception is thrown because of the usage of a generic type. It is concerning the ASP.NET MVC binding rather the Kendo UI suite. 

The Kendo UI editors are dependent on the built-in features of the ASP.NET MVC Framework. For instance, we are creating editor templates which derive from the editors provided by ASP.NET MVC. As I was conducting research on the exception in hand, I have noticed that the main concern is that there are missing fields. There were numerous suggestions on how to decorate the fields in order to resolve the case. Nevertheless, when using a dynamic type, there are no fields, hence, this creates an indirect limitation. 

This limitation comes from the generic type and the Kendo UI team does not have control over the processing of such types. The main point why the grid is functioning with the Popup edit mode is that the editor used is actually an Html helper - Html.EditorForModel().  On the contrary, when using the InLine or InCell edit modes, each of the editors is created against one of the fields in the model. At the time the editor requests for the field, the error is thrown. 

I hope you find those clarifications helpful.


Kind regards,
Tsvetomir
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Christian
Top achievements
Rank 1
Answers by
Tsvetomir
Telerik team
Christian
Top achievements
Rank 1
Share this question
or