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

Foreign key column problem

10 Answers 398 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dina
Top achievements
Rank 1
Dina asked on 05 Jan 2015, 06:12 PM
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

10 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 07 Jan 2015, 02:14 PM
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.

 
0
Dina
Top achievements
Rank 1
answered on 07 Jan 2015, 03:47 PM
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

0
Dina
Top achievements
Rank 1
answered on 07 Jan 2015, 03:57 PM
and more, Problem only in edit mode. In grid column works - show title of foreign table data
0
Vladimir Iliev
Telerik team
answered on 08 Jan 2015, 08:21 AM
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.

 
0
Dina
Top achievements
Rank 1
answered on 08 Jan 2015, 10:28 AM
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
0
Dina
Top achievements
Rank 1
answered on 08 Jan 2015, 10:30 AM
Damn, my reply was blocked by antispam
0
Dina
Top achievements
Rank 1
answered on 08 Jan 2015, 05:14 PM
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.
0
GarfieldTech
Top achievements
Rank 1
answered on 23 Jun 2019, 01:19 PM

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-(.

0
Alex Hajigeorgieva
Telerik team
answered on 26 Jun 2019, 07:55 AM
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.
0
GarfieldTech
Top achievements
Rank 1
answered on 26 Jun 2019, 07:02 PM

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

Tags
Grid
Asked by
Dina
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Dina
Top achievements
Rank 1
GarfieldTech
Top achievements
Rank 1
Alex Hajigeorgieva
Telerik team
Share this question
or