I use a role-based menu. I have to generate the menu from the database dynamically. I have a role mapping table from which I can get the functions that appear in the role. Once I get this, I need to generate an HTML menu with <ul> and <li> . May I get a suggestion on how to do this. I mean creating an HTML script in the controller and mapping it to the appropriate view. Please help. Any suggestions are welcome.
<ul id="menu"> <li> @Html.ActionLink("Home", "Dashboard", "User") </li> <li> <a href="#"><span>User</span></a> <ul> <li>@Html.ActionLink("Create User", "CreateUser", "User")</li> </ul> </li> <li> <a href="#"><span>Report</span></a> <ul> <li>@Html.ActionLink("ABC Report", "ABC", "Report")</li> <li>@Html.ActionLink("User Report", "UserReport", "Report")</li> </ul> </li> <li> <a href="#"><span>XYZ</span></a> <ul> <li>@Html.ActionLink("XYZ1", "XYZ1", "XYZ")</li> <li>@Html.ActionLink("XYZ2", "XYZ2", "XYZ")</li> <li>@Html.ActionLink("XYZ3", "XYZ3", "XYZ")</li> <li>@Html.ActionLink("XYZ4", "XYZ4", "XYZ")</li> </ul> </li> </ul>
Over HTML, I have to build a controller and render the view.
source share