This is a migrated thread and some comments may be shown as answers.
LoadOnDemand Does Not Wire Node Url
3 Answers 51 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nathan Taylor
Top achievements
Rank 1
Nathan Taylor asked on 10 Jun 2010, 01:39 AM
I am working with a LoadOnDemand TreeView and I noticed that setting a Url property for a dynamically loaded field does not get reflected/wired up in the rendered output.

public ActionResult GetFiles(TreeViewItem node) { 
    string appPath = Server.MapPath("~/"); 
    Predicate<string> nameFilter = p => p != ".svn"
    Func<stringstring> pathSelector = p => p.Replace(appPath, "/").Replace(Path.DirectorySeparatorChar, '/'); 
 
    if (node == null || string.IsNullOrEmpty(node.Value)) { 
        string path = Server.MapPath("~/Content/UserFiles/Files/_private"); 
 
        var items = SafeIO.GetDirectoryTree(path, SearchOption.TopDirectoryOnly, nameFilter, pathSelector); 
 
        return View("DisplayTemplates/DirectoryTree", items.ToArray()); 
    } 
    else { 
        string path = Server.MapPath("~" + node.Value); 
 
        var nodes = SafeIO.GetDirectoryTree(path, SearchOption.TopDirectoryOnly, nameFilter, pathSelector) 
                    .Select(pathItem => new TreeViewItem() { 
                            Text = pathItem.Name, 
                            Value = pathItem.FullPath, 
                            Url = (pathItem is FileItem) ? pathItem.FullPath : null
                            LoadOnDemand = (pathItem is DirectoryItem), 
                            Enabled = true 
                        }); 
 
        return Json(nodes.ToArray()); 
    } 

Checking the JSON returned I can confirm that the Url is being sent in the response, however the rendered nodes do not have an href: value set:

[{"Items":[], 
"Value":"/Content/UserFiles/Files/_private/Foo/shippingapicredentials.txt"
"Text":"shippingapicredentials.txt"
"Url":"/Content/UserFiles/Files/_private/Foo/shippingapicredentials.txt"
"LoadOnDemand":false
"Expanded":false,"Checked":false,"RouteName":null,"HtmlAttributes":[],"ImageHtmlAttributes":[],"LinkHtmlAttributes":[],"Visible":true,"ImageUrl":null,"SpriteCssClasses":null,"Selected":false,"Enabled":true,"ControllerName":null,"ActionName":null,"RouteValues":[],"ContentHtmlAttributes":[],"Content":null,"Parent":null,"PreviousSibling":null,"NextSibling":null}] 

<ul class="t-group" style="display: block;"
    <li class="t-item t-last"
        <div class="t-bot"
            <span class="t-in t-state-selected">shippingapicredentials.txt</span></div
        <input type="hidden" value="/Content/UserFiles/Files/_private/Foo/shippingapicredentials.txt" 
            name="itemValue" class="t-input"></li></ul



3 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 15 Jun 2010, 09:57 AM
Hello Nathan,

You should return a TreeViewItemModel enumeration rather than a TreeViewItem one -- the TreeViewItemModel it has a NavigateUrl property that is used on the client (and the links will show up).

It seems to me, however, that the TreeViewItemModel is quite redundant. If a substitution with the TreeViewItem class is plausible, we might obsolete this approach for the upcoming release - your solution just feels right and, as a bonus, might reduce our codebase. Thank you for guiding us towards this.

Sincerely yours,
Alex Gyoshev
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Nathan Taylor
Top achievements
Rank 1
answered on 15 Jun 2010, 05:32 PM
Thank you for the response. I meant to post this with my original post, but for some reason I never worked it in. I too was wondering about the redundancy of TreeViewItem vs TreeViewItemModel because as you say they serve the same functional purpose. The problem is that I tested this problem with that model type as well (as you demonstrate in the LoadOnDemand demo), but even that one was not binding the Url. With either type the treeview was getting populated correctly, but the Url was not.

I just realized I have been using SP1 rather than SP2 of the MVC kit. I will report back whether the problem is still present in SP2 shortly.
0
Alex Gyoshev
Telerik team
answered on 16 Jun 2010, 09:49 AM
Hello Nathan,

Indeed, the NavigateUrl didn't render in the link tag, even when using the TreeViewItemModel binding. I am sorry that I misguided you.-- after my post yesterday I went ahead to cover this functionality with javascript tests and the problem showed up. It can be easily fixed in the telerik.treeview.js, getGroupHtml function. Just change the line
    html.cat(item.NavigateUrl ? '<a class="t-link t-in">' : '<span class="t-in">');
to
    html.cat(item.NavigateUrl ? '<a class="t-link t-in" href="' + item.NavigateUrl + '">' : '<span class="t-in">');

(you can even substitute the NavigateUrl property with an Url one and your previous code will work)

The problem is fixed for future builds.

All the best,
Alex Gyoshev
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
Tags
TreeView
Asked by
Nathan Taylor
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Nathan Taylor
Top achievements
Rank 1
Share this question
or