1) Add a class named "CustomHHelpers" in your model folder.
@Html.getTopMenu(@Url.Content("~/"+@ViewContext.RouteData.Values["controller"].ToString()))
namespace MvcApplication2.Models { public static class CustomHHelpers { public static MvcHtmlString getTopMenu(this HtmlHelper htmlHelper,
string url) { StringBuilder sbMenu = new StringBuilder(); sbMenu.Append("<ul>"); sbMenu.Append("<li><a href=\"" + url + "\">Home</a></li>"); var menus = menuItems.insertDemoData(); foreach (var m in menus) { sbMenu.Append("<li><a href=\"" + url + "\\" + m.url + "\">"
+ m.urlName + "</a></li>"); } //==== Close dynamic menu unordered list. sbMenu.Append(" <li><a href=\"#\">Contact Us</a></li>"); sbMenu.Append("</ul>"); return MvcHtmlString.Create(sbMenu.ToString()); } } public class menuItems { public int Id { get; set; } public string urlName { get; set; } public string url { get; set; } public static List<menuItems> insertDemoData() { List<menuItems> obj = new List<menuItems>(); obj.Add(new menuItems { Id = 1,
urlName = "Anketler", url = "Anketler" }); obj.Add(new menuItems { Id = 1,
urlName = "Duyurular", url = "Duyurular" }); obj.Add(new menuItems { Id = 1,
urlName = "Kullanıcı Profili", url = "Profil" }); return obj; } } }
2) Use in your _Layout.html or where you want to use:@Html.getTopMenu(@Url.Content("~/"+@ViewContext.RouteData.Values["controller"].ToString()))