views:

490

answers:

5

is any library to allow create dynamic javascript menu from code ?

+1  A: 

If you are using ASP controls like <ASP:MENU>, the dropdown effect is javascript-ed by the control at the server-side. You should be able to use it in ASP.NET MVC too.

See Leveraging Existing ASP.NET Features in ASP.NET MVC

Another good example is WebForm validations, the client-side validation scripts are all generated dynamically at the server-side.

UPDATE
This is probably what you are looking for:
ASP.NET and JQuery MVC Menu and Part 2

o.k.w
in asp.net mvc there is no controls like <ASP:MENU>, no webforms am i right? so this is a problem, guess i need to write my own menu
kusanagi
It is possible, just not pretty. Refer to the link in my post. As what the other guys have answered, if you can generate the menu in markups like unordered list, throwing in some jQuery other JS framework plugins + CSS will do the trick. Most require no server-side javascript generation. I've added a link in my updated answer to a tutorial which might help.
o.k.w
I hate to be the mvc nazi but you should completely eliminate the usage of most server controls when using mvc. It detracts from the TDD capabilities of the framework as well as it just looks plain ugly.
Al Katawazi
A: 

try superfish - i use it in almost all of my MVC apps.

don't forget to upvote this or mark it as an answer if it's useful :)

benpage
A: 

My understanding is that a primary benefit of the MVC framework is that you have complete control of the presentation layer markup. As such, you can tailor it to match pretty much any javascript based menuing system. You can build a lot of great systems with jQuery, for instance.

DA
but how? :) i know, there no "controls" but i need any idea\example
kusanagi
How what? What part are you unsure about/what part do you need an example of? The basic concept: Via ASP.net, you generate proper HTML markup (typically nested unordered lists). Via javascript, you manipulate that markup to create the type of menu you want. Via CSS you style it. Suckerfish (and all the varients) are good examples of menus like that.
DA
+1  A: 

Just use plain jane UL/LI and use the javascript to do the visual effects. Tons of menu's out on the net that operate this way.

Example:

<UL>
<% foreach(var item in ViewData["MyMenu"]){%>
<LI><%= item.Title %></LI>
<%} %>
</UL>
Al Katawazi
and how you show\hide subitems?
kusanagi
Well you can use something like this http://users.tpg.com.au/j_birch/plugins/superfish/#ab. But if you want to do it yourself a simle <li onMouseover='ShowSubMenu()'><%= item.Title %></li> and then you would write the javascript for that show menu command. It should look like this function ShowSubMenu(){$("#MySubMenuID").show();} . If you have no idea what I am talking about find a pre built jQuery based menu system and use that, there are tons on the internet. Also see this site too http://plugins.jquery.com/project/jQuery-Horizontal-Menu
Al Katawazi
A: 

I have used Telerik Mvc Extensions in my mvc apps. They are free and really easy to work with. Plus the skinning feature along with http://www.telerik.com/products/aspnet-ajax/visual-style-builder.aspx can make the extensions feel like home with any site design. The extensions are written in JQuery.

dionysus55
are you sure that they absolutelly free?
kusanagi
they are licensed under GPL v2.0, so if you are not using the controls to make money they are then free to use. So if you are going to package the controls in a product that you plan to sell then you need a commercial license.
dionysus55