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

Default editor for Foreign Key column and models field names

4 Answers 152 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pawel Ch
Top achievements
Rank 1
Pawel Ch asked on 20 Jun 2016, 02:21 PM

I found following problem:

I have one main view MainView with two different partial views ViewOne and ViewTwo returned to the main view by separate @HTML.RenderAction(Action, controller) methods from different controllers . The partial views renders Ajax form with model fields in the first view and  KendoDataGrid in the second partial view.Both views uses different data models but  one field in each model has the same name. eg ForeignKey_ID.

When I try to edit a row in the second view (data grid) the row goes to edit state but instead of a dropdown with names/labels for ForeignKey_ID a text box with default id numerical value appears. In the same time missing dropdown shows up just by the dropdown for  ForeignKey_ID field in the first partial view (Ajax form)

I tried to use different field in the second view (datagrid) so there was no the same field name in the whole page and then expected dropdown with dictionary values shown up properly.

It can be solved by changing affected field name in the model.

Is there any other solution for this ?

 

 

ForeignKey_ID

4 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 22 Jun 2016, 08:21 AM
Hello Pawel,

The issue in question is due to the equal IDs generated for the editor. You could however add the following to the editor template for the ForeignKey column (GridForeignKey.asxc/cshtml):
.HtmlAttributes(new { id = Guid.NewGuid().ToString() })

And here is modified template:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<object>" %>
 
<%= Html.Kendo().DropDownListFor(m => m)  
    .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])
    .HtmlAttributes(new { id = Guid.NewGuid().ToString() })
%>

Hope this helps.


Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Pawel Ch
Top achievements
Rank 1
answered on 25 Jul 2016, 10:15 PM

Hello Konstantin

The solution you proposed works fine for the standard editor template. Howewer my problem is a little bit more complex.

In the problematic dataGrid I have to use custom template for the foreign key column with dropdown presenting filtered data and cascaded from a standard foreign key column. Code of the template below

@model Nullable<int>
@(Html.Kendo().DropDownListFor(m => m)
.AutoBind(false)
.OptionLabel("Select ...")
.DataTextField("Name")
.DataValueField("ID")
.ValuePrimitive(true)
.DataSource(source =>
{
source.Read(read => { read.Action("GetParentAreasJSON", "Area").Data("filterLocations_AP_T_FIFA"); })
.ServerFiltering(true);
})
.CascadeFrom("Sys_LocationID")
)
@Html.ValidationMessageFor(m => m)

question is how to do the same for that code ?

When i try to add id attribute code below it shows dropdown in edit mode but it doesnt expand as it should

.HtmlAttributes(new { id = Guid.NewGuid().ToString() })

 

Best Regards

Pawel Chmielewski

0
Pawel Ch
Top achievements
Rank 1
answered on 27 Jul 2016, 08:11 AM

Unfortunately used solution has some bad side effect ...

In a datagrid where foreign key column (column A) which uses standard template is used to cascade another foreign key column (column B) which uses custom template (with data filtering ) using generated GUID as id attribute in standard template causes column A to be unreachable for column B filtering code.

Solution with id is ok as long as there is no cascading dependency in a grid.  

 

0
Konstantin Dikov
Telerik team
answered on 27 Jul 2016, 11:20 AM
Hello Pawel,

Please examine the example in the following HowTo article for implementing cascading DropDownList in the Grid:

Best Regards,
Konstantin Dikov
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Pawel Ch
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Pawel Ch
Top achievements
Rank 1
Share this question
or