Foreign key column problem

11 posts, 0 answers
  1. Dina
    Dina avatar
    50 posts
    Member since:
    Feb 2012

    Posted 05 Jan 2015 Link to this post

    Having grid with 2 foreign key columns. Grid shows them as is should - value from foreign column (matched by ID)

    But in edit mode I have Integer field instead of drop down in one of them.

    Models and EditTemplate absolutely identical (as I see)
    Problem is in Teachers

    Here is models

       [DisplayName("Level")]
            [UIHint("Level")]
            public int LevelId
            {
                get;
                set;
            }

            [DisplayName("Teacher")]
            [UIHint("Teacher")]
            public int TeacherId
            {
                get;
                set;
            }

    here is Level.cshtml
    @model object
               
    @(
     Html.Kendo().DropDownListFor(m => m)
                            .BindTo((System.Collections.IEnumerable)ViewData["levels"]).DataTextField("Title").DataValueField("Id")
    )


    here Teacher.cshtml
    @model object
               
    @(
     Html.Kendo().DropDownListFor(m => m)
                                .BindTo((System.Collections.IEnumerable)ViewData["teachers"]).DataTextField("Name").DataValueField("TeacherId")
    )

    also
    ViewData["teachers"]) populated as
      var dataContext = new EntitiesModel();
                var items = dataContext.Peoples
                            .Select(c => new TeachersViewModel
                            {
                                TeacherId = c.HumanId,
                                Name = c.nme + " " + c.Surname,
                                OccupationId = c.OccupationId
                            }).Where(p => p.OccupationId == 2)
                            .OrderBy(e => e.Name);
                ViewData["teachers"] = items;
                ViewData["defaulteacher"] = items.First();

    Still do`nt get why one of column don want to be dropdown
  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2206 posts

    Posted 07 Jan 2015 Link to this post

    Hi Dima,

    I tried to reproduce the issue on our side but to no avail - everything is working as expected. Could you please modify the attached example to reproduce the issue and send it back to us? This would help us pinpoint the exact reason for current behavior.

    Regards,
    Vladimir Iliev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Dina
    Dina avatar
    50 posts
    Member since:
    Feb 2012

    Posted 07 Jan 2015 Link to this post

    Seems I meet problem only then using EntityModel (telerik data access)

    I compared my project (I used mvc demo then coding it of course). All the same.
    Seems like I missing some key factor triggering grid to ignore UIHint (I changed to [UIHint("GridForeignKey")] as in your example and also copied GridForeignKey.cshtml)

    Grid seems like randomly show this issue. Some foreign key columns show dropdows some not but model, view, controller seems damn identical

  4. Dina
    Dina avatar
    50 posts
    Member since:
    Feb 2012

    Posted 07 Jan 2015 in reply to Dina Link to this post

    and more, Problem only in edit mode. In grid column works - show title of foreign table data
  5. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2206 posts

    Posted 08 Jan 2015 Link to this post

    Hi Dima,

    Basically the ORM that is used on the server side should not have any effect on the editor templates of the Grid. Current behavior is either related to JavaScript errors on the page (you can check the browser console) or both editors have the same "id" attribute - could you please check these suggestions and let us know of the result?

    Regards,
    Vladimir Iliev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Dina
    Dina avatar
    50 posts
    Member since:
    Feb 2012

    Posted 08 Jan 2015 Link to this post

    I thought about same Id already (was in my project) so I chnged it al to CourseId, StatusId and so on

    JS errors
    Во время загрузки страницы соединение с ws://localhost:29722/cb0bf73a2b9946398669ac659893d39d/arterySignalR/connect?transport=webSockets&connectionToken=AQAAANCMnd8BFdERjHoAwE%2FCl%2BsBAAAAqwMhtxDa402DLv6wWd1bdQAAAAACAAAAAAAQZgAAAAEAACAAAAAs1PpQbPlLQwTia9zQy3N9m8s6RdXSEJ6M4pi8Ravh%2BAAAAAAOgAAAAAIAACAAAADhuOD7ZFBFKLOZlMBRoKF%2BWjYEQk%2BX3EFqogXE%2FwVztjAAAAD7SGKPUJWl8RdOTWfYb8SnX0Fb76SKa2k1V6d6jQBwsKoUj0xiEDplhEp%2BNQ8pDmZAAAAALPKnXwCFP%2BDmCLN9QX%2FGippNC1n687xoqEOLGgsPkPWBpIcClm86%2BwaQxnyLptHWM6Q5wvr4a5VV8ni%2FvHOLCQ%3D%3D&requestUrl=http%3A%2F%2Flocalhost%3A12269%2FSecretaryArea%2FStudents&browserName=Firefox&userAgent=Mozilla%2F5.0+(Windows+NT+6.3%3B+WOW64%3B+rv%3A34.0)+Gecko%2F20100101+Firefox%2F34.0&tid=0 было прервано. browserLink:62
    элемент не найден abort:1
    Using //@ to indicate sourceMappingURL pragmas is deprecated. Use //# instead jquery.min.js:1
    Метод getPreventDefault() является устаревшим. Для его замены используйте метод defaultPrevented.

    first error say connection was interrupted,


    worst thing is - now I add new tables to my main one (with working foreign columns) in this new objects again show as integer fields in editor. Looks like I stupidly missing one thing that is very obvious
  7. Dina
    Dina avatar
    50 posts
    Member since:
    Feb 2012

    Posted 08 Jan 2015 in reply to Vladimir Iliev Link to this post

    Damn, my reply was blocked by antispam
  8. Dina
    Dina avatar
    50 posts
    Member since:
    Feb 2012

    Posted 08 Jan 2015 in reply to Vladimir Iliev Link to this post

    I am very sorry. Damn stupid I am

    found EditorTemplates folder in Views folder not in Views / Shared. Seems like incidental move by mouse.

    Thread closed.
  9. GarfieldTech
    GarfieldTech avatar
    11 posts
    Member since:
    Jun 2015

    Posted 23 Jun 2019 Link to this post

    Hello,  I have similar problem as this, but I set up as Telerik UI Asp.Net MVC...  I am new with Telerik MVC, and following the instruction for just first time from Foreign Key Column (https://demos.telerik.com/aspnet-mvc/grid/foreignkeycolumn). 

    I am unable to correct or resolve PopularCategories(); in ForeignKeyColumnController.  I have followed DropDownList ForeignKey column in View/ForeignKeyColumn.cshtml.

    I added editor template in ~View\Shared\EditorTemplates named GridForeignKey.cshtml and added @model object.

    I checked ForeignKeyColumnController, and PopulateCategories(); still getting red underline error? It said the "PopulateCategories does not exist in current context."

    I saw other posted about DataSource or DefaultCategory that I need to add? 

    I have played and learn others within Grid using different instruction except ForeignKeyColumn 8-(.

  10. Alex Hajigeorgieva
    Admin
    Alex Hajigeorgieva avatar
    1082 posts

    Posted 26 Jun 2019 Link to this post

    Hello, David,

    I am sorry to hear that the demo description is not clear enough. I read through the description and I agree that can be improved so I logged an internal task for us to enhance it.

    The PolulateCategories() method is invoked in the controller action which returns the view and here is what it does:

    private void PopulateCategories()
    {
     using (var dataContext = new SampleEntitiesDataContext())
     {
         var categories = dataContext.Categories
                     .Select(c => new CategoryViewModel
                     {
                         CategoryID = c.CategoryID,
                         CategoryName = c.CategoryName
                     })
                     .OrderBy(e => e.CategoryName);
     
         ViewData["categories"] = categories.ToList();
         ViewData["defaultCategory"] = categories.First();
       }
    }

    It creates a list (or it could be a SelectList) of the foreign key column texts and values. The ViewData["categories"] is used to provide the text representation of the foreign key column values in the grid template, the other two parameters show which is the value and which is the text field:

    columns.ForeignKey(p => p.CategoryID, (System.Collections.IEnumerable)ViewData["categories"], "CategoryID", "CategoryName")

    The same collection is used to populate the dropdown list in the GridForeignKey.cshtml

    The default category is needed for Create operations.

    Let me know if you need more information.

    Kind Regards,
    Alex Hajigeorgieva
    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.
  11. GarfieldTech
    GarfieldTech avatar
    11 posts
    Member since:
    Jun 2015

    Posted 26 Jun 2019 in reply to Alex Hajigeorgieva Link to this post

    Awesome and thank you for your quick prompt response with PopulateCategories() explanation!

Back to Top