How to Bind a Grid to a Property of an Object

2 posts, 0 answers
  1. Randal
    Randal avatar
    2 posts
    Member since:
    May 2006

    Posted 15 Aug Link to this post

    I am unable to create a new record, i.e. nothing pops up, when my grid is bound to my Person.Employer's EmployerName string property. 

    @model IList<EmployeeManager.Web.EmployeeServiceRef.Person>
    @(Html.Kendo().Grid(Model)
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(p => p.PersonName);
            columns.Bound(p => p.PhoneNumber);
            columns.Bound(p => p.Employer.EmployerName);
            columns.Bound(p => p.Address);
        })
        .ToolBar(toolbar => toolbar.Create())
        .Editable(editable => editable.Mode(GridEditMode.PopUp))

    When I comment out p.Employer.EmployerName, the New button pops up a dialog as expected. Is there any way I can bind my Employee object to the grid so that I can edit these details as well? The plan is to create a dropdown list of the Employer Name's once I can figure out how to bind it to an Add New call.

    Any help would be greatly appreciated.

  2. Randal
    Randal avatar
    2 posts
    Member since:
    May 2006

    Posted 15 Aug in reply to Randal Link to this post

    I finally figured it out. I had to create a default value in my datasource so that the Employer object could be initialized.

     

    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(25)
        .Model(model =>
        {
            model.Id(p => p.Id);
            model.Field(p => p.Family).DefaultValue(new EmployeeManager.Web.UI.EmployeeServiceRef.Employer());
        })

  3. Kendo UI is VS 2017 Ready
Back to Top