this is my code in the helper class
public static string GenerateMenu(this HtmlHelper helper)
{
var items = GetAllMenuItems();
bool isIndex = false;
var currentUrl = HttpContext.Current.Request.Url;
StringBuilder menu = new StringBuilder();
if (currentUrl.AbsolutePath == "/")
{
isIndex = true;
}
menu.AppendLine("<ul class=\"layout-menu\">");
foreach (var item in items)
{
menu.Append("<li><a ");
if (isIndex)
{
if (items.First() == item)
{
menu.Append("class=\"menuItemSelected\" ");
}
}
if(currentUrl.AbsolutePath.ToLower().Contains(item.NavigateURL.ToLower()))
{
menu.Append("class=\"menuItemSelected\" ");
}
menu.Append("href=\"" + item.NavigateURL + "\">");
menu.Append(item.Text);
menu.Append("</a></li>" + Environment.NewLine);
}
menu.AppendLine("</ul>");
return menu.ToString();
}
Im displaying it using
@Html.GenerateMenu()
It renders it perfectly but not as functional objects but only as plain text, any help ?
Thanks
since you are using mvc3 you can use the HtmlString