Populating a dropdown in the detail of a master/detail

Does anyone have an example of how to populate a dropdown column in the detail grid of a master/detail using UrlAdaptor?

My column definition looks like this:

        {
            new Syncfusion.EJ2.Grids.GridColumn() {Field="ReferencedTableName", HeaderText="Referenced Table Name", IsPrimaryKey=true, Visible=false, AutoFit=true, CustomAttributes=new { @@class="e-attr" }}, 
            new Syncfusion.EJ2.Grids.GridColumn() {Field="TableName", HeaderText="Table Name", IsPrimaryKey=true, AutoFit=true,  ForeignKeyField="TableName", ForeignKeyValue="TableNameDesc", DataSource="@ViewBag.Tables", EditType="dropdownedit", CustomAttributes=new { @@class="e-attr" }}, 
            new Syncfusion.EJ2.Grids.GridColumn() {Field="ColumnName", HeaderText="Column Name", IsPrimaryKey=true, AutoFit=true, CustomAttributes=new { @@class="e-attr" }}
        }

One problem is that the code in the controller that populates Viewbag.Tables is not being run for the detail grid (see below). What complicates things a little further is that I have dropdown column named ReferenceTableName in the master which is being populated with the same data properly, and I am populating Viewbag.Tables exactly the same way in the master controller.  I can populate a different Viewbag variable if needed.

        public ActionResult Index()
        {
            var Tables = (from p in _context.Tables orderby p.TableName
                           select new { p.TableName,
                                        TableNameDesc = p.TableName }).ToList();

            ViewBag.Tables = Tables;

            return View("Views/Basic/DropdownsDetail.cshtml",Navigation.GetTableList(_context));
        }
    }


3 Replies 1 reply marked as answer

TS Thiyagu Subramani Syncfusion Team December 24, 2020 02:08 AM UTC

Hi Harvey, 

Thanks for contacting Syncfusion support. 

Based on your shared information we have prepared a sample as per your requirement at our end. But unfortunately your reported issue doesn’t reproduced. Please refer to the below code and sample link.  

Columns = new List<Syncfusion.EJ2.Grids.GridColumn> { 
new Syncfusion.EJ2.Grids.GridColumn(){ Field="UnitID", IsPrimaryKey=true, HeaderText="Unit ID"}, 
new Syncfusion.EJ2.Grids.GridColumn(){ Field="ShipName", HeaderText="Ship Name", AutoFit= true,  EditType="dropdownedit", DataSource=(IEnumerable<object>)ViewBag.DataSource, ForeignKeyField="ShipName", ForeignKeyValue="ShipCountry"  }, 
new Syncfusion.EJ2.Grids.GridColumn(){ Field="EmployeeID", HeaderText="Ship Address" }, 



If Still facing the issue, please share below detail, 

1.  Share complete master and detail grid rendering code. 

2. Syncfusion package version 

3. If possible share issue reproducing sample or reproduce the issue in above sample. 

Please get back to us, if you need any further assistance. 

Regards, 
Thiyagu S. 


Marked as answer

HK Harvey Kravis December 24, 2020 02:59 PM UTC

I needed to define my datasource as you showed using IEnumerable.  Thanks so much for this quick and accurate response.  You folks never let me down.

DataSource=(IEnumerable<object>)ViewBag.Tables


TS Thiyagu Subramani Syncfusion Team December 28, 2020 04:25 AM UTC

Hi Harvey, 

Thanks for the update.  

We are happy to hear that the provided solution was helpful to achieve your requirement. Please let us know if you have any concerns. 

Regards, 
Thiyagu S 


Loader.
Up arrow icon