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

Same name in different controlles in TreeView?

4 Answers 79 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.
dejavu
Top achievements
Rank 2
dejavu asked on 13 Oct 2010, 01:11 PM
Is this possible?, i know this can be achieved using regular html helpers (Html.ActionLink and so), but i couldn't get it to work using TreeView control.

Version is 2010.2.815, .NET Framework 3.5 on C#, no others plugins or view engines other than webforms default one.

Any suggestions?

Regards.

#EDIT: just need to be more concise: my test environment has two areas, named Test and Test2, each one with a controller named Home. Additionally, at root level exists another controller also named Home. Just using out-of-the-box MVC 2 html helpers (like Html.ActionLink), there's no problem at all. But, when i change to a Telerik MVC 2 TreeView helper app brokes.

4 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 13 Oct 2010, 03:54 PM
Hello dejavu,

I am not exactly sure how exactly you are using treeview UI component in order to generate correct URL depending on the Area. Did you try something like this:
subItem.Add()
       .Text("Personal Folders")
       .Action("Index", "Home", new { Area = "AreaName" });

If the problem still persists I will ask you to send us a simple test project, which reproduces the depicted issue.

Regards,
Georgi Krustev
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
dejavu
Top achievements
Rank 2
answered on 13 Oct 2010, 07:08 PM
Thanks for your quick response. Sample app is attached.

Anyway, problem is when two (or more) controller classes with the same name coexists on different areas. Don't know if this is a issue with MVC 2 itself (and the routing mechanism), but specifying Area = "AREA_NAME" on each item in Telerik's TreeView doesn't work.

This is my navigation View User Control, with a simple TreeView:

<%
        Html.Telerik().TreeView()
            .Name("Menu")
            .Items(item =>
            {
                item.Add()
                    .Text("Inicio")
                    .Action("Index", "Home", new { Area = string.Empty })
                    .Items(subItem =>
                    {
                        subItem.Add()
                            .Action("Index", "Home", new { Area = string.Empty })
                            .Text("Index");
                    });
                item.Add()
                    .Text("Test")
                    .Action("Index", "Ejemplo", new { Area = "Test" })
                    .Items(subItem =>
                    {
                        subItem.Add()
                            .Action("Index", "Ejemplo", new { Area = "Test" })
                            .Text("Index");
                    });
                item.Add()
                    .Text("Test 2")
                    .Action("Index", "Ejemplo", new { Area = "Test2" })
                    .Items(subItem =>
                    {
                        subItem.Add()
                            .Action("Index", "Ejemplo", new { Area = "Test2" })
                            .Text("Index");
                    });
            }).Render();
    %>

And registration on each area route:

context.MapRoute(
                "Test", // Route name
                "Test/{controller}/{action}/{id}", // URL with parameters
                new { controller = "Ejemplo", action = "Index", id = UrlParameter.Optional },
                null,
                new[] { "MvcApplication1.Areas.Test.Controllers" }
            );

...and the other one...

context.MapRoute(
                "Test2", // Route name
                "Test2/{controller}/{action}/{id}", // URL with parameters
                new { controller = "Ejemplo", action = "Index", id = UrlParameter.Optional },
                null,
                new[] { "MvcApplication1.Areas.Test2.Controllers" }
            );


Adding a controller at the root level named like the ones causing the problem fix this scenario, but that's far from what i've been trying to acomplish.

Thanks againg for your help, Georgi.

Regards,
dejavu.
0
Accepted
Georgi Krustev
Telerik team
answered on 18 Oct 2010, 09:11 AM
Hello dejavu,

In order to achieve your goal you will need to use URL method of the TreeViewItem object like so:
<%
    Html.Telerik().TreeView()
        .Name("Menu")
        .Items(item =>
        {
            item.Add()
                .Text("Inicio")
                .Url(Url.Action("Index", "Home", new { Area = string.Empty }, null))
                .Items(subItem =>
                {
                    subItem.Add()
                        .Url(Url.Action("Index", "Home", new { Area = string.Empty }, null))
                        .Text("Index");
                });
            item.Add()
                .Text("Test")
                .Url(Url.Action("Index", "Ejemplo", new { Area = "Test" }))
                .Items(subItem =>
                {
                    subItem.Add()
                        .Url(Url.Action("Index", "Ejemplo", new { Area = "Test" }))
                        .Text("Index");
                });
            item.Add()
                .Text("Test 2")
                .Url(Url.Action("Index", "Ejemplo", new { Area = "Test2" }))
                .Items(subItem =>
                {
                    subItem.Add()
                        .Url(Url.Action("Index", "Ejemplo", new { Area = "Test2" }))
                        .Text("Index");
                });
        })
        .HighlightPath(true)
        .Render();
%>

In next official release of the Telerik Components for ASP.NET MVC. you will be able to use Action method of the TreeViewItem object to achieve the same behavior.

Best regards,
Georgi Krustev
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
dejavu
Top achievements
Rank 2
answered on 18 Oct 2010, 07:14 PM
Thanks again for your time.

I've already notice this, and although it's not what i've wanted, it works as supposed to. I appreciate your help Georgi, and wait that official release as soon as you and your people can release it.

Thanks again.

regards,
dejavu.
Tags
TreeView
Asked by
dejavu
Top achievements
Rank 2
Answers by
Georgi Krustev
Telerik team
dejavu
Top achievements
Rank 2
Share this question
or