Hey Georgi,
I am interested in using the ForeignKeyColumn Tag-Helper, however I have found that it does not work in my project while the ForeignKeyColumn HTML-Helper does work. I attached the two approaches, they are almost indentical but the ForeignKeyColumns behave differently:
@(Html.Kendo().Grid<
Data.CarModel
>()
.Name("modelGridWorking")
.Columns(c => {
c.ForeignKey("BrandId", Model.Brands, "BrandId", "BrandName").Title("Marke").Width(100);
c.Bound("ModelName").Title("Modell").Width(100);
c.Bound("Description").Title("Beschreibung").Width(200);
c.Bound("Locked").Title("Gesperrt").Width(50);
c.Command(cmd => cmd.Edit()).Width(120);
c.Command(cmd => cmd.Destroy()).Width(120);
})
.DataSource(c => {
c.Ajax()
.ServerOperation(true)
.Read(o => o.Url("ModelManagement?handler=Read").Data("forgeryToken"))
.Create(o => o.Url("ModelManagement?handler=Create").Data("forgeryToken"))
.Update(o => o.Url("ModelManagement?handler=Update").Data("forgeryToken"))
.Destroy(o => o.Url("ModelManagement?handler=Destroy").Data("forgeryToken"))
.Model(m => {
m.Id("ModelId");
m.Field("ModelName", typeof(String));
m.Field("Description", typeof(String));
m.Field("Locked", typeof(Boolean));
});
})
.Editable(GridEditMode.InLine)
.Pageable(c => {
c.Refresh(true).ButtonCount(5).PageSizes(new[] { 10, 20, 50 });
})
.Groupable(true)
.Sortable(true)
)
<
kendo-grid
name
=
"modelGridNotWorking"
>
<
columns
>
<
foreign-key-column
title
=
"Marke"
width
=
"100"
field
=
"BrandId"
values
=
"Model.Brands"
value-field
=
"BrandId"
text-field
=
"BrandName"
></
foreign-key-column
>
<
column
title
=
"Modell"
width
=
"100"
field
=
"ModelName"
></
column
>
<
column
title
=
"Beschreibung"
width
=
"200"
field
=
"Description"
></
column
>
<
column
title
=
"Gesperrt"
width
=
"50"
field
=
"Locked"
></
column
>
<
column
width
=
"120"
>
<
commands
>
<
column-command
text
=
"Bearbeiten"
name
=
"edit"
></
column-command
>
</
commands
>
</
column
>
<
column
width
=
"120"
>
<
commands
>
<
column-command
text
=
"Löschen"
name
=
"destroy"
></
column-command
>
</
commands
>
</
column
>
</
columns
>
<
datasource
type
=
"DataSourceTagHelperType.Ajax"
page-size
=
"20"
>
<
transport
>
<
read
url
=
"ModelManagement?handler=Read"
data
=
"forgeryToken"
/>
<
create
url
=
"ModelManagement?handler=Create"
data
=
"forgeryToken"
/>
<
update
url
=
"ModelManagement?handler=Update"
data
=
"forgeryToken"
/>
<
destroy
url
=
"ModelManagement?handler=Destroy"
data
=
"forgeryToken"
/>
</
transport
>
<
schema
>
<
model
id
=
"ModelId"
>
<
fields
>
<
field
name
=
"ModelName"
type
=
"String"
></
field
>
<
field
name
=
"ModelDescription"
type
=
"String"
></
field
>
<
field
name
=
"Locked"
type
=
"Boolean"
></
field
>
</
fields
>
</
model
>
</
schema
>
</
datasource
>
<
editable
mode
=
"inline"
enabled
=
"true"
/>
<
pageable
button-count
=
"5"
refresh
=
"true"
page-sizes
=
"new int[] { 10, 20, 50 }"
></
pageable
>
<
groupable
enabled
=
"true"
/>
<
sortable
enabled
=
"true"
/>
</
kendo-grid
>
In the Model, i am populating the public Property Brands as follows:
public
IEnumerable<CarBrand> Brands {
get
;
set
; }
public
IActionResult OnGet()
{
Brands = _context.CarBrand.ToList();
}
Note the I also tried to use the ViewData instead of a property but the result is the same. Do you have any idea why the ForeignKeyColumn in the first example works as expected (displays the Brand name instead of BrandId) but the later does not (displays BrandId, also when editing it shows an Integer-Editor instead of a DropDown)?