Default editor for Foreign Key column and models field names

5 posts, 0 answers
  1. Pawel Ch
    Pawel Ch avatar
    4 posts
    Member since:
    May 2015

    Posted 20 Jun Link to this post

    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
  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1793 posts

    Posted 22 Jun Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Pawel Ch
    Pawel Ch avatar
    4 posts
    Member since:
    May 2015

    Posted 25 Jul in reply to Konstantin Dikov Link to this post

    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

  5. Pawel Ch
    Pawel Ch avatar
    4 posts
    Member since:
    May 2015

    Posted 27 Jul Link to this post

    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.  

     

  6. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1793 posts

    Posted 27 Jul Link to this post

    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready