This question is locked. New answers and comments are not allowed.
I am trying to use the TreeView component to mimic a file and folder tree. I've already written the code to pull the directory structure, but when the data is bound to the TreeView it is skipping objects in the output even though I have explicitly defined a binding instruction for them. If I manually create the folder and file information object in the view (rather than pulling it from the file system) the exact same binding code renders the TreeView correctly. I have confirmed that the data being returned by the file and folder iterator is properly constructed, but for some reason the FileItem objects never make it into the markup.
Here is the make up of my model items
Here is the code I am using to render the view:
As I said above, the FileItem is never rendered in the output even though I have confirmed that the data in the Model contains multiple FileItems and the debugger is stepping into the For<FileItem>() binding with a valid FileItem reference.
As a test, if I pass the following object to the BindTo() method everything works as expected:
So to recap, the code I am binding the TreeView with works fine for all DirectoryInfo objects regardless, but fails to render any output for FileInfo objects if the FileInfo objects are being created dynamically rather than manually.
Any thoughts?
Here is the make up of my model items
| public abstract class PathItem |
| { |
| public string Name { get; set; } |
| public string FullPath { get; set; } |
| } |
| public class DirectoryItem : PathItem |
| { |
| public PathItem[] Paths { get; set; } |
| } |
| public class FileItem : PathItem |
| { |
| public long Size { get; set; } |
| } |
Here is the code I am using to render the view:
| <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<PathItem>>" %> |
| <% Html.Telerik().TreeView() |
| .Name("Files") |
| .BindTo(Model, mappings => { |
| mappings.For<DirectoryItem>(binding => binding |
| .ItemDataBound((item, directory) => { |
| item.Text = directory.Name; |
| }) |
| .Children(directory => directory.Paths)); |
| mappings.For<FileItem>(binding => binding |
| .ItemDataBound((item, file) => { |
| item.Text = file.Name; |
| item.Url = file.FullPath; |
| })); |
| }).Render(); %> |
As I said above, the FileItem is never rendered in the output even though I have confirmed that the data in the Model contains multiple FileItems and the debugger is stepping into the For<FileItem>() binding with a valid FileItem reference.
As a test, if I pass the following object to the BindTo() method everything works as expected:
| var data = new PathItem[] { |
| new DirectoryItem() { |
| FullPath = "", |
| Name = "Search Engines", |
| Paths = new PathItem[] { |
| new FileItem() {FullPath = "http://www.google.com", Name = "Google"}, |
| new FileItem() {FullPath = "http://www.bing.com", Name = "Bing"}, |
| new FileItem() {FullPath = "http://www.yahoo.com", Name = "Yahoo"}, |
| new DirectoryItem() { |
| FullPath = "", |
| Name = "Old", |
| Paths = new PathItem[] { |
| new FileItem() {FullPath = "http://www.altavista.com", Name = "AltaVista"}, |
| } |
| } |
| } |
| }, |
| new FileItem() {FullPath = "http://www.digg.com", Name = "Digg"} |
| }; |
So to recap, the code I am binding the TreeView with works fine for all DirectoryInfo objects regardless, but fails to render any output for FileInfo objects if the FileInfo objects are being created dynamically rather than manually.
Any thoughts?