i have data in sting values in html format how to apply css and jquery styles
public class Menus
{
public List<Menus> GetALL { get; set; }
public int menuId { get; set; }
public string menuName { get; set; }
public string menuURL { get; set; }
public int parentId { get; set; }
}
public class MenuModel
{
public MenuItemsEntities objEntities = new MenuItemsEntities();
public string GetMenu()
{
//Get MainMenu Menus
Menus menuobj = new Menus();
var objmenu = from menus in objEntities.MenuItems
where menus.ParentId == 0
select menus;
string strMenuBuild = string.Empty;
strMenuBuild += "<ul>";
foreach (var i in objmenu)
{
menuobj.menuName = i.ItemName;
menuobj.menuId = i.MenuItemsID;
menuobj.menuURL = i.URL;
if (i.ParentId == 0)
{
//GetSubMenu();
strMenuBuild = strMenuBuild + "<li><a href='" + menuobj.menuURL + "'>" + menuobj.menuName + "</a><ul>";
strMenuBuild += GetSubMenu(Convert.ToInt32(menuobj.menuId)) + "</ul></li>";
//strMenuBuild += "</ul></li>";
}
}
strMenuBuild += "</ul>";
return strMenuBuild;
}
public string GetSubMenu(int submenuid)
{
string strSubBuild = string.Empty;
Menus menuobj = new Menus();
var submenu= from menus in objEntities.MenuItems
where menus.ParentId == submenuid
select menus;
if (submenu.Count() > 0)
{
foreach (var sbmnu in submenu)
{
menuobj.menuURL = sbmnu.URL;
menuobj.menuName = sbmnu.ItemName;
menuobj.menuId = sbmnu.MenuItemsID;
strSubBuild = strSubBuild + "<li ><a href='" + menuobj.menuURL + "'>" + menuobj.menuName + "</a>";
var submneu1 = from menus in objEntities.MenuItems
where menus.ParentId == menuobj.menuId
select menus;
if (submneu1.Count() > 0)
{
strSubBuild += "<ul>";
strSubBuild += GetSubMenu(Convert.ToInt32(menuobj.menuId));
strSubBuild += "</ul>";
}
strSubBuild += "</li>";
}
}
return strSubBuild;
}
}
I have return to String In Html formate like that
But am bind the Menus and submenus .i want appy the css and jquery.how to apply Css and jquery i dont know .can any one help me please..
This is the function I use to build up my menu structure:
var buildMenu = function(menu, el) {
var ul = $('<ul></ul>');
ul.appendTo(el);
for(var i in menu) {
var menuItem = $('<li><a href="' + menu[i].url + '">' + menu[i].title + '</a></li>');
menuItem.appendTo(ul);
if(menu[i].subMenu) {
buildMenu(menu[i].subMenu, menuItem);
};
};
}
menu being th JSON object that contains the menu and el being the div or containing element to insert the menu into.
My Menu object has the following format:
var menu : [{
title : 'Home',
url : 'Default.html'
}, {
title : 'Groups',
url : '#',
subMenu : [{
title : 'Group1',
url : 'Group1.html'
},{
title : 'Group2',
url : 'group2.html'
}]
}];
Hope that helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.