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

ForeignKey does not show in grid.

6 Answers 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alan Mosley
Top achievements
Rank 1
Alan Mosley asked on 02 Aug 2013, 01:49 AM
I have set a value to my ForeignKey colum in the controller before being sent to the grid. I can see that it is populated in the response body, but not ForeignKey dropdown is visible, when I click then I get the dropdown.

My ForeignKey editor template and below my grid

Thanks

@ModelType Object
@code
    Dim DropDown As Kendo.Mvc.UI.DropDownList = Html.Kendo().DropDownListFor(Function(m) m).BindTo(CType(ViewData(ViewData.TemplateInfo.GetFullHtmlFieldName(String.Empty) & "_Data"), SelectList))
 
    DropDown.Render()
    End Code

@ModelType IEnumerable(Of EF.Team)
@code
    Dim CsvGrid As Kendo.Mvc.UI.Grid(Of BO.Models.Contractor.CsvUploadData) = Html.Kendo.Grid(Of BO.Models.Contractor.CsvUploadData).Name("CsvGrid") _
.Columns(Sub(columns)
                 columns.Bound(Function(c) c.FirstName)
                 columns.Bound(Function(c) c.LastName)
                 columns.Bound(Function(c) c.Email)
                 columns.Bound(Function(c) c.FirstbookingDate)
                 columns.Bound(Function(c) c.FullService)
                 columns.Bound(Function(c) c.PoolSize)
                 columns.Bound(Function(c) c.Spa)
                 columns.Bound(Function(c) c.Street)
                 columns.Bound(Function(c) c.Zipcode)
                 columns.ForeignKey(Function(f) f.TeamId, Model, "TeamId", "Name").Width(200).Title("Team")
                 columns.Command(Function(Command) Command.Destroy())
         End Sub) _
.ToolBar(Sub(toolbar)
                 toolbar.Create()
                 toolbar.Save()
         End Sub) _
    .Editable(Function(editable) editable.Mode(GridEditMode.InCell)) _
    .Pageable() _
    .Navigatable() _
    .Sortable() _
    .Scrollable() _
.DataSource(Function(dataSource) dataSource _
    .Ajax() _
    .Batch(True) _
    .ServerOperation(False) _
    .Events(Function(events) events.Error("CsvUpload.GridEditError")) _
    .Model(Sub(Model)
                   Model.Id(Function(d) d.CsvUploadDataId)
                   Model.Field(Function(f) f.TeamId).DefaultValue(1)
           End Sub) _
    .Create("Editing_Create", "Grid") _
    .Read("csvuploadgriddata", "services", New With {.area = String.Empty}) _
    .Update("Editing_Update", "Grid") _
    .Destroy("Editing_Destroy", "Grid"))
 
                   CsvGrid.Render()
 
End Code

6 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 05 Aug 2013, 03:50 PM
Hello Alan,

 Your ForeignKey configuration expects that the Model of your view contains the list of foreign key values. Is this the case? This is indicated by the second argument of the ForeignKey method:

columns.ForeignKey(Function(f) f.TeamId, Model, "TeamId", "Name").Width(200).Title("Team")

 Is the Model set properly in the action method that renders this view? You can paste that action method's code here so we can check it out.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Alan Mosley
Top achievements
Rank 1
answered on 06 Aug 2013, 01:03 AM

Thanks for your reply, yes the model does hold the key values, this we know is correct because when you click on the empty team column, the dropdown appears, but is empty till you do. The dropdown shows Team1, but is not actually selected and shows blank again when losing focus, if you choose team 2, the value is then shown when losing focus, then you can choose team1.
This grid is loaded via ajax in a partial view, am I supposed to fire some event or something after load?

Thanks


Function ReadCsvUploadGridData(<Kendo.Mvc.UI.DataSourceRequestAttribute()> request As Kendo.Mvc.UI.DataSourceRequest) As JsonResult
    Dim CsvUploadData As IEnumerable(Of BO.Models.Contractor.CsvUploadData) = CType(Session("uploadedCsvs"), IEnumerable(Of BO.Models.Contractor.CsvUploadData))
 
    For i As Integer = 0 To CsvUploadData.Count - 1
        CsvUploadData(i).TeamId = 1
    Next
    Return Json(CsvUploadData.ToDataSourceResult(request))
End Function
0
Atanas Korchev
Telerik team
answered on 06 Aug 2013, 07:40 AM
Hello Alan,

We need the action method which renders the grid partial view. It is the one which should populate the Model with the list of teams.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Alan Mosley
Top achievements
Rank 1
answered on 06 Aug 2013, 08:16 AM
No problems

Function CsvUploadGrid(id As Integer) As PartialViewResult
    Dim CsvUploadDatas As IEnumerable(Of BO.Models.Contractor.CsvUploadData) = CType(Session("uploadedCsvs"), IEnumerable(Of BO.Models.Contractor.CsvUploadData))
    If CsvUploadDatas Is Nothing Then
        Return PartialView("_CsvUploadError")
    End If
    Dim errors As BO.Models.Contractor.CsvErrors = BO.Factory.ContractorFactory.SortErrors(CsvUploadDatas)
    If errors.Count > 0 Then
        Return PartialView("_CsvUploadErrors", errors)
    End If
    Dim contractor As EF.Contractor = db.Contractors.Include(Function(i) i.Teams).Single(Function(g) g.ContractorId.Equals(id))
    Return PartialView("_CsvGrid", contractor.Teams)
End Function
0
Atanas Korchev
Telerik team
answered on 06 Aug 2013, 09:28 AM
Hello Alan,

 The code looks correct and should work if the Teams property is not empty. Could you please verify if this is not the case? If not we would ask you to open a support ticket and attach a runnable subset of your project which we can troubleshoot.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Alan Mosley
Top achievements
Rank 1
answered on 07 Aug 2013, 09:21 AM
Thanks
I found problem or lack of problem, the ids did not match a teamId in database, was looking at production database and running of development database, sorry to waste your time.
Thanks again
Tags
Grid
Asked by
Alan Mosley
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Alan Mosley
Top achievements
Rank 1
Share this question
or