Question

How can I add styling(htmlattribute) to each item while menu bind to web.sitemap

web.sitemap

<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
  <siteMapNode title="Home" controller="Home" action="Overview">
    <siteMapNode title="Grid">
      <siteMapNode controller="grid" action="index" title="First Look (Razor)" area="razor"/>
      <siteMapNode controller="grid" action="index" title="First Look (ASPX)" area="aspx"/>
    </siteMapNode>
    <siteMapNode title="Menu">
      <siteMapNode controller="menu" action="index" title="First Look (Razor)" area="razor"/>
      <siteMapNode controller="menu" action="index" title="First Look (ASPX)" area="aspx"/>
    </siteMapNode>
  </siteMapNode>
</siteMap>

Kendo Menu Binding to web.sitemap

Html.Kendo().Menu()
.Name("Menu")
.BindTo("web", (item, value) => {                                        
       if(item.Text.Equals("Home"))                                        
       {                                            
            item.Enabled = false;
            // how can i add css style to the item here                            
       }                                       
})
.Render();

Thanks

Was it helpful?

Solution

found the solution to apply css to each menu item with condition

Html.Kendo().Menu()
.Name("Menu")
.BindTo("web", (item, value) => {                                        
        if(item.Text.Equals("Home"))                                        
        {   
             item.Enabled = false;
             item.HtmlAttributes.Add("style", "background-color:#CCCCCC;");
             item.LinkHtmlAttributes.Add("style", "font-weight:bold; color:black;");
        }                                       
 })
 .Render();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top