This is a migrated thread and some comments may be shown as answers.

Pass data to EditorTemplateName

1 Answer 340 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Edward
Top achievements
Rank 1
Edward asked on 31 Dec 2018, 07:38 PM

Have a Grid.cshtml page which has one dropdown which is defined by a EditorTemplateName named ValueViewTemplate.cshtml (below).... Would like to add more dropdowns to the Grid.cshmtl.  Currently seems like have to add more EditorTemplateName templates for each dropdown.  Is there way to pass in the ViewData to the EditorTemplateName function so don't have to define a editor template for each dropdown?

Also current pages seems to work for InCell and InLine... Is there way to make it work for Popup for does there need to be additional templates defined for the Popup option for editable mode...

 

Grid.cshtml

@(Html.Kendo().Grid<NEP_Deconstruction.Data.Models.ApprovalViewModel>()
                .Name("approval_grid")
                .Columns(columns =>
                {
                    columns.Bound(o => o.ApprovalNumber);
                    columns.Bound(o => o.ApprovalName);
                    columns.Bound(o => o.Comment);
                    columns.ForeignKey(o => o.ApprovalCountryID, (System.Collections.IEnumerable)ViewData["ApprovalCountry"], "ID", "Value")
                    .EditorTemplateName("ValueViewTemplate");
                    columns.Bound(o => o.EffectiveDate);
                    columns.Command(command => { command.Edit(); command.Destroy(); }).Width(210);
                })

                .ToolBar(toolbar => toolbar.Create())
                .Editable(editable => editable.Mode(GridEditMode.InLine))

 

 

 

 

ValueViewTemplate.cshtml

@model NEP_Deconstruction.Data.Models.ValueViewModel

@(Html.Kendo().DropDownListFor(m => m)
                .DataValueField("ID")
                .DataTextField("Value")
                .BindTo((System.Collections.IEnumerable)ViewData["ApprovalCountry"])
)

 

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 02 Jan 2019, 09:19 AM
Hi Edward,

When using ForeignKey column the Grid will use a partial view that is located in ~/Views/Shared/EditorTemplates folder. The name of the partial view will be GridForeignKey.cshtml by default. That editor will be used by all foreign key columns in the Grid and the ViewData will be passed to it automatically. 

Check out the example below that illustrates how to setup a ForeignKey column in the Grid:



Regards,
Viktor Tachev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Edward
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or