Click here to Skip to main content
15,887,434 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hello Friends,
I am new to MVC tool,plz can anyone help me how to create a dynamic menu using C#3.0, XSLT, Javascript, linq(for ex: here in codeproject site there is a menu above like Home,Articles & so on).Dynamically have to create, edit, delete menu.

Regards
Madhusudhan
Posted

Here are the topics you'll want to read up on:

1) Master pages
2) Partial views
3) CSS styling

A good MVC approach to this would be creating a partial view that renders some LI elements in a UL list.

The partial view will be called/rendered on your master page, thus making it available site-wide.

You'll use CSS to make the UL/LI elements look like a menu instead of just a bulleted list.

You can, of course, use ASP.NET membership, Linq to SQL etc. Google for ScottGu's article's on MVC, or check out the ASP.NET MVC site[^] for a good start.

Cheers.
 
Share this answer
 
If you create the menus using an HtmlHelper Extension method like:

<%= Html.RenderMenu() %>
you can use the HtmlHelper instance to look at the request context and determine what page you are on. Once you have this you can lookup (database, configuration, where ever your menu data is...) which submenu to render.

Heres something to get you point in the direction I think you are looking for:

public static MvcHtmlString RenderMenu(this HtmlHelper html)
{ var somePage = Html.ViewContext.HttpContext.Request.RawUrl;
var menu = lookupMenuBasedOnPage(somePage);
return MvcHtmlString.Create(menu.Render());
 
Share this answer
 

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