New to Telerik UI for ASP.NET Core? Download free 30-day trial
ASP.NET Core Grid ForeignKey Column
- EXAMPLE
- VIEW SOURCE
-
Change Theme
defaultDefault Theme
- Main
- Main Dark
- Nordic
- Ocean Blue
- Ocean Blue A11Y
- Purple
- Turquoise
Bootstrap Theme- Main
- Bootstrap 3
- Bootstrap 3 Dark
- Main Dark
- Nordic
- Turquoise
- Turquoise Dark
- Urban
- Vintage
Material Theme- Main
- Arctic
- Lime Dark
- Main Dark
- Nova
Classic Theme- Main
- Green
- Green Dark
- Lavender
- Lavender Dark
- Main Dark
- Metro
- Metro Dark
- Moonlight
- Opal
- Opal Dark
- Silver
- Silver Dark
- Uniform
Fluent Theme- Main
Also available for:
CLIENT-SIDE API SERVER-SIDE APIDescription
The ForeignKey column functionality of the Telerik UI for ASP.NET MVC Grid component is primarily used for matching the value of a bound property to a desired text field from a collection that is external for the Data Grid. The ForeignKey column feature follows the convention of the SQL ForeignKey functionality that is used for linking two tables based on a foreign key.
This example shows how to implement a foreign-key column in the
ASP.NET Core Data Grid, which generates an ASP.NET Core DropDownList editor for
its Category column. To define the ForeignKey column, set columns.ForeignKey(p => p.CategoryID,(System.Collections.IEnumerable)ViewData["categories"],"CategoryID","CategoryName").Title("Category").Width(150);
.
When a column is defined as a ForeignKey column, the Data Grid will look for the GridForeignKey.cshtml
editor template in the ~Views\\Shared\\EditorTemplates
folder, and populate it with the passed collection through the column declaration. To set the editor template, use the following definition:
@model object
@(Html.Kendo().DropDownListFor(m => m)
.BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("")+
"_Data"])
In addition to the Foreign Key editor template, you can populate a list which holds all the categories and pass it through the ViewData
. For the specific configuration, refer to the ForeignKeyColumnController.cs
PopulateCategories()
method.
If you are going to use Create
operations, provide a DefaultCategory
in the DataSource Model
field.
For more information about the ForeignKey column capabilities, refer to the official Telerik UI for ASP.NET Core Data Grid product documentation on the available fltering approaches.