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