Hi!
I use Kendo UI for MVC 2016.1.301, with MVC 6 (Core 1.0). I have a grid with some fixed (bound) columns, and a few dynamic columns. I have managed to add the columns dynamically, with titles. The data type for these dynamic columns are bool. I've found various samples but none of them works, either they don't compile or they have no effect. I must add I'm new to the Razor engine so I don't understand exactly what's happening at all times.
So, how do I replace the [X] with data from the view model? I've tried variations on this theme, using .Bound and .Template, but nothing compiles either compile-time or run-time:
1.
for
(
int
i = 0; i < Model.PresetsList.PresetsList.Count(); i++)
2.
{
3.
string
titel = Model.PresetsList.PresetsList[i].PresetsName;
4.
int
columnIndex = i;
5.
columns.Bound(cgi => cgi.MadeChoicePresetsList[columnIndex].IsSelected.ToString()).Title(titel);
6.
}
Here's the current code which displays a [X] instead of data:
01.
@(Html.Kendo().Grid<C.ViewModels.ChoiceGroupItemViewModel>()
02.
.Name(
"choicegroupitemsgrid"
)
03.
.Columns(columns =>
04.
{
05.
columns.Bound(col => col.ChoiceGroupID).Title(
"gruppID"
);
06.
columns.Bound(col => col.ItemID).Title(
"artikelID"
);
07.
columns.Bound(col => col.ManufacturerItemID).Title(
"Tillv. artikelnr"
);
08.
columns.Bound(col => col.ItemName).Title(
"Benämning"
);
09.
columns.Bound(col => col.CustomerPayablePriceInclTax).Title(
"Pris"
).HtmlAttributes(
new
{ align =
"right"
});
10.
11.
foreach
(var presets
in
Model.PresetsList.PresetsList)
12.
{
13.
columns.Template(
"[X]"
).Title(presets.PresetsName);
14.
}
15.
}
16.
)
17.
.Scrollable()
18.
.Pageable(pgbl => pgbl
19.
.Refresh(
true
)
20.
.PageSizes(
true
)
21.
.ButtonCount(5)
22.
)
23.
.Sortable(sortable => { sortable.SortMode(GridSortMode.SingleColumn); })
24.
.DataSource(datasrc => datasrc
25.
.Ajax()
26.
.Read(read => read
27.
.Action(
"ChoiceGroupItems"
,
"ChoiceGroup"
,
new
{ area =
"Backoffice"
, id = Model.ChoiceGroupID })
28.
)
29.
.PageSize(20)
30.
)
31.
32.
)