Create item in treelist fail if Id or ParentId is nullable

2 posts, 0 answers
  1. Christophe
    Christophe avatar
    1 posts
    Member since:
    Dec 2015

    Posted 27 Jan Link to this post

    When using TreeList widget with a simple model like this:

    public class MyModel
    {
         public int? Id {get;set;}
         public int? ParentId {get;set;}
         public string Name {get;set;}
    }

    ...

    @(Html.Kendo().TreeList<MyModel>().Name("treeList")
        .Toolbar(t=>t.Create())
        .Editable(e=>e.Mode("popup"))
        .DataSource(ds=>ds
              .Model(m=>
              {
                   m.Id(f=>f.Id);
                   m.ParentId(f=>f.ParentId);
                   m.Field(f=>f.Name);
              })
             .Create(c=>c.Action("Create", "My"))
            )
            .Columns(c=>
            {
    c.Add().Field(f=>f.Id);
    c.Add().Field(f=>f.ParentId)
    c.Add().Field(f=>f.Name)
            })
    )

    When filling the popup, there are no error, but the item is NOT inserted in the treeList. If I change the type of the Id and ParentId to non nullable, the problem is solved.

    In your demo, the model seems to have nullable fields as Id and ParentId, but there are no demo of item creation. Is it a bug or something missing in my code?When using TreeList widget with a simple model like this:

    public class MyModel
    {
         public int? Id {get;set;}
         public int? ParentId {get;set;}
         public string Name {get;set;}
    }

    ...

    @(Html.Kendo().TreeList<MyModel>().Name("treeList")
        .Toolbar(t=>t.Create())
        .Editable(e=>e.Mode("popup"))
        .DataSource(ds=>ds
              .Model(m=>
              {
                   m.Id(f=>f.Id);
                   m.ParentId(f=>f.ParentId);
                   m.Field(f=>f.Name);
              })
             .Create(c=>c.Action("Create", "My"))
            )
            .Columns(c=>
            {
    c.Add().Field(f=>f.Id);
    c.Add().Field(f=>f.ParentId)
    c.Add().Field(f=>f.Name)
            })
    )

    When filling the popup, there are no error, but the item is NOT inserted in the treeList. If I change the type of the Id and ParentId to non nullable, the problem is solved.

    In your demo, the model seems to have nullable fields as Id and ParentId, but there are no demo of item creation. Is it a bug or something missing in my code?

     

    Regards

  2. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 29 Jan Link to this post

    Hello Christophe,

    The editing demo shows creation of records. The model itself can be seen in the GitHub repository. A nullable Id field does not seem to make sense, since the Id should be unique. The ParentId can be nullable (for indicating root-level items).

    Regards,
    Alex Gyoshev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top