Foreign key in kendo MVC grid foreign key

1 Answer 49 Views
Grid
Mahesh
Top achievements
Rank 1
Iron
Mahesh asked on 12 Dec 2023, 03:12 PM

I am trying to bind the datatable to the MVC grid and using ajax read to get the data. Everything is working as expected until I am trying to convert one of the column to foreignkey column.

Here is my sample code

 @(Html.Kendo().Grid<dynamic>()
                .Name("ReportGrid")
                .Scrollable()
                .Columns(columns =>
                {
                    foreach (var column in Model.TableConfig.MasterColumns)
                    {
                        if (refColumns.Contains(column.ColumnName))
                        {
                            var refData = Model.MetaData.Where(m => m.ColumnName == column.ColumnName).ToList();


                            columns.ForeignKey(column.ColumnName, new SelectList(refData, "DataValue","DataText")).EditorTemplateName("GridForeignKey");


                        }
                        else
                        {
                            columns.Bound(column.ColumnName);
                        }
                        //var c = columns.Bound(column.ColumnName);
                    }                
                })

 

I am getting the below error

 

System.AggregateException: 'One or more errors occurred. ('object' does not contain a definition for 'DataTable ColumnName')'

1 Answer, 1 is accepted

Sort by
0
Mahesh
Top achievements
Rank 1
Iron
answered on 14 Dec 2023, 05:59 PM
Anton Mironov
Telerik team
commented on 15 Dec 2023, 08:06 AM

Hi Mahesh,

Thank you for sharing the resolution approach with the community.

The following demo represents the recommended implementation of the ForeignKey column in a Grid:

The following article provides the needed documentation for using a ForeignKey column:

 

Kind Regards,
Anton Mironov

Tags
Grid
Asked by
Mahesh
Top achievements
Rank 1
Iron
Answers by
Mahesh
Top achievements
Rank 1
Iron
Share this question
or