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

[Solved] BindTo() code is broken

1 Answer 80 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rich
Top achievements
Rank 1
Rich asked on 09 Apr 2012, 08:39 PM
Using Razor.  I can import the model at the top of the view without a problem;
@model IEnumerable<NtaWebPortal.Models.FilterCategory>


But then FilterCategory and FilterChild are cannot be found in the rest of the view code:

@{Html.Telerik().TreeView()
        .Name("TreeView")
        .ShowCheckBox(true)
        .BindTo(Model, mappings =>
             
            {
                mappings.For<FilterCategory>(binding => binding
                    .ItemDataBound((item, category) =>
                    {
                        item.Text = category.ParentName;
                    })
                    .Children(category => category.Children));
            
                    mappings.For<FilterChild>(binding => binding
                    .ItemDataBound((item, child) =>
                    {
                        item.Text = child.childName;
                    }));
            }
         
        )
        .Render();
         
    }
I get a "type or namespace name could not be found".

Not sure if I have built my Model incorrectly...the example on the demos site doesn't include and example of model code.

Any ideas on whats wrong?  Any full code examples out there of binding  a treeview to a DB that someone would like to share?

1 Answer, 1 is accepted

Sort by
0
Rich
Top achievements
Rank 1
answered on 09 Apr 2012, 10:34 PM
Solved - it was a faulty model...failing around on the internet help me create the correct code:
    public class FilterCategory
    {
        public string ParentName {get; set;}
        FilterCategory category;
        public List<FilterChild> Children { get; set; }
    }
}

I was originally missing the FilterCategory property.  Honestly, this doesn't make sense to me.  How can you have a property of a class that is the class itself?  If anyone has any references to this programming practice, I would love to read more.

Tags
TreeView
Asked by
Rich
Top achievements
Rank 1
Answers by
Rich
Top achievements
Rank 1
Share this question
or