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

Create item in treelist fail if Id or ParentId is nullable

1 Answer 158 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Christophe
Top achievements
Rank 1
Christophe asked on 27 Jan 2016, 02:37 PM

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

1 Answer, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 29 Jan 2016, 03:56 PM

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
Tags
TreeList
Asked by
Christophe
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Share this question
or