Telerik mvc grid, columns.bound - the value of the dictionary. or "dynamic property in model"

I have a model with dynamic "properties" (at the database level, something similar to the Entity-Attribute-Value system ). The properties are in the Dictionary<int, string> field and would like to display them in columns.

Model:

the model has a static array (initialized in a static contextum) of the names of "properties" and keys:

  public static ModelSpecialParameter[] SpecialFields; 

and a dictionary (initialized in the create model, and all possible keys are added) with their values.

 public Dictionary<int, string> ValuesForDynamicProps; 

View :

 @(Html.Kendo().Grid(Model) .Name("grid") .Columns(columns => { //other columns for realy propertry //columns.Bound(e => ... //columns.Bound(e => ... foreach (var item in SpecialFields) // SpecialFields is a static collection. represent the name an id of the dynamic property's. { columns.Bound("ValuesForDynamicProps[" + item.IdProperty + "]").Width(140).Title(item.DisplayName); } } 

I get an error message:

{"Linked columns require expressions to access a field or properties." }

I also tried:

 columns.Bound(e => e.ValuesForDynamicProps[item.IdProperty]).Width(140).Title(item.DisplayName); 

same mistake.

Even if what I want is impossible. I am looking for an idea how to get the desired result: Flexibility in adding and removing properties.

+8
asp.net-mvc telerik-mvc
source share
2 answers

There is no easy way to do this directly with the Fluent API. What you have to do is make an ajax call to another method that will return JSON with this structured data all in one.

Or try it differently, it's almost the same idea you tried. Maybe it can help you: https://mycodepad.wordpress.com/2014/12/01/asp-net-mvc-5-with-razor-kendo-ui-dynamic-grid-creation-columns-ordering-grouping -and-paging /

+1
source share

As far as I understand, you have a problem:

 columns.Bound(e => ValuesForDynamicProps[item.IdProperty]).Width(140).Title(item.DisplayName); 

You go to the lambda Bound() method, but don't use its parameter (model). It should be something like:

 columns.Bound(e => e.ValuesForDynamicProps[item.IdProperty]).Width(140).Title(item.DisplayName); 
0
source share

All Articles