Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I created menu using MVC5 sitemapmenuprovider, In the xml document I added URL's and Roles of the user and based on role I am displaying the menu.

<mvcSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0"
            xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0 MvcSiteMapSchema.xsd">
  <mvcSiteMapNode url="~/Home/About" title="About" description="" Roles="Admin" visibility="true" ></mvcSiteMapNode>
 
    <mvcSiteMapNode url="~/Home/Contact" title="Contact" description="" Roles="User" visibility="true"></mvcSiteMapNode>

   
    </mvcSiteMapNode>
</mvcSiteMap>


What I have tried:

I want to add other conditions by connecting with database from MVC controller.

but below code from Layout page
@Html.MvcSiteMap().Menu()
does not hitting any controller.

Its directly going to Partial view and displaying the menu

@model MvcSiteMapProvider.Web.Html.Models.SiteMapHelperModel
@using System.Web.Mvc.Html
@using MvcSiteMapProvider.Web.Html.Models

<ul class="siteMap">
    @foreach (var node in Model.Nodes) { 
        <li>@Html.DisplayFor(m => node) 
            @if (node.Children.Any()) {
                @Html.DisplayFor(m => node.Children)
            }
        </li>
    }
</ul>


My question is before going to view is there any possibility to keep conditions in controller and change the node visibility from controller.

How to load the menu by checking conditions by connecting database using
sitemapmenuprovider in MVC5
Posted
Updated 17-Dec-19 8:21am
v2
Comments
dnxit 23-Dec-19 0:49am    
Not using Site Map but menu is coming from the database, check this article
https://www.codeproject.com/Articles/5163177/MVC-6-Dynamic-Navigation-Menu-from-Database

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900