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

[Solved] Menu "Html" to Telerik.Menu Question

2 Answers 89 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tubs
Top achievements
Rank 1
Tubs asked on 17 Dec 2009, 03:52 PM
Hi,

I've run into a bit of a problem ... I currently have a solution that renders a perfectly good menu on pure HTML and I have tried all sorts of ways to get the Telerik Menu to work. Yet dont seem to get the right method.

Important points are that I already have Route Values via RoutevalueDictionary (see NavController Menu() and a View that Renders the HTML well with no problems.

Controller: (webproductsRepository is where the data is)

    public class NavController : Controller  
    {  
        private IWebProductsRepository webProductsRepository;  
        public NavController(IWebProductsRepository webProductsRepository)  
        {  
            this.webProductsRepository = webProductsRepository;  
        }  
 
        public ViewResult Menu(string highlightCategory)  
        {  
            // Put a Home link at the top  
            List<NavLink> navLinks = new List<NavLink>();  
            navLinks.Add(new CategoryLink(nullnull)  
            {  
                IsSelected = (highlightCategory == null)  
            });  
 
            // Add a link for each distinct category  
            var categories = webProductsRepository.WebProducts.Select(x => new 
            {  
                urlCategory = x.WebURLProductCategory,  
                displayCategory = x.WebProductCategory  
            }).AsEnumerable().Distinct().OrderBy(x => x.displayCategory);  
 
            foreach (var category in categories)  
                navLinks.Add(new CategoryLink(category.displayCategory, category.urlCategory)  
                {  
                    IsSelected = (category.urlCategory == highlightCategory)  
                });  
 
            return View(navLinks);  
        }  
 
 
    }  
 
    public class NavLink // Represents a link to any arbitrary route entry  
    {  
        public string Text { getset; }  
        public RouteValueDictionary RouteValues { getset; }  
        public bool IsSelected { getset; }  
    }  
    public class CategoryLink : NavLink // Specifically a link to a product category  
    {  
        public CategoryLink(string displayCategory, string urlCategory)  
        {  
            Text = displayCategory ?? "Home"// <--- This is where the text is added  
            RouteValues = new RouteValueDictionary(new 
            {  
                controller = "WebProducts",  
                action = "List",  
                category = urlCategory,  
                page = 1  
            });  
        }  
    }  

The View (partial) is as follows:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<WebUI.Controllers.NavLink>>" %> 
<% foreach (var link in Model)  
   {%> 
    <href="<%= Url.RouteUrl(link.RouteValues) %>" 
    class="<%= link.IsSelected ? "selected" : "" %>" 
    > 
        <%= link.Text %> 
    </a> 
<% } %> 

Please let me know where and how I can integrate the Telerik.Menu (Ive Tried BindingTo ... which didnt work) and fiddled with the View .. to no avail.

Regards

Tubs

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 17 Dec 2009, 04:07 PM
Hi Tubs,

 I suggest you check the BindTo method of the menu. Here is an online example which you can observe. Have in mind the demonstrated overload has been introduced with the SP1 release from last week.


Greetings,
Atanas Korchev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Tubs
Top achievements
Rank 1
answered on 17 Dec 2009, 04:20 PM
Hi Atanas,

Thanks fo rthe quick response and the tips. 

Regards

Tubs
Tags
Menu
Asked by
Tubs
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Tubs
Top achievements
Rank 1
Share this question
or