ForeignKey does not show in grid.

7 posts, 0 answers
  1. Alan Mosley
    Alan Mosley avatar
    200 posts
    Member since:
    Apr 2010

    Posted 01 Aug 2013 Link to this post

    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
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 05 Aug 2013 Link to this post

    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!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Alan Mosley
    Alan Mosley avatar
    200 posts
    Member since:
    Apr 2010

    Posted 05 Aug 2013 Link to this post

    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
  5. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 06 Aug 2013 Link to this post

    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!
  6. Alan Mosley
    Alan Mosley avatar
    200 posts
    Member since:
    Apr 2010

    Posted 06 Aug 2013 Link to this post

    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
  7. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 06 Aug 2013 Link to this post

    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!
  8. Alan Mosley
    Alan Mosley avatar
    200 posts
    Member since:
    Apr 2010

    Posted 07 Aug 2013 Link to this post

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