mary
mary

Reputation: 431

How to create dynamic menu in asp.net mvc?

How to create dynamic menu on views in asp.net mvc 2.0?

Upvotes: 1

Views: 2049

Answers (2)

Amitabh
Amitabh

Reputation: 61167

Use JQuery menu.

http://p.sohei.org/stuff/jquery/menu/demo/demo.html

Use controller to build ViewData for menu. Build the Menu in view by iterating over the ViewData for Menu.

Upvotes: 0

Alxandr
Alxandr

Reputation: 12423

Could you be a bit more spesific maybe?

If it's just a list of links it's easy enough, you just loop trough them an output a link with the Html.Action helper.

Something like:

<div class="menu">
<% // From the Controller we got the following list of links as a IEnumerable<String> { "Home", "About" } put in Model.
foreach(var lAddr in Model) { %>
    <%= Html.Action(lAddr, lAddr) %><br />
<% } %>
</div>

This should hender something like (if in an Controller named Home):

<a href="/Home/Home">Home</a><br /><a href="/Home/About">About</a>

Upvotes: 2

Related Questions