This question is locked. New answers and comments are not allowed.
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)
The View (partial) is as follows:
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
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(null, null) |
| { |
| 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 { get; set; } |
| public RouteValueDictionary RouteValues { get; set; } |
| public bool IsSelected { get; set; } |
| } |
| 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) |
| {%> |
| <a 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