In asp.net mvc 4 and mvc 5. How to mange menu in Xml file?. In mvc web application individual user assigned menu is store in separate xml file.
and user login only open assigned menu not other menu. If user is type another page url is going to error page

Surendra KandiraRank #3,063 · 462 pointsPosted Jul 14, 2015, 11:59 PM EDT
Create menu model... public class menu { public List Module { get; set; } } public class Module { public string name { get; set; } public List form { get; set; } } public class Form { public string name {get;set;} public string link { get; set; } public bool access { get; set; } public List form1 { get; set; } } public class Form1 { public string name{get;set;} public string link { get; set; } public bool access { get; set; } } Create menu Action ... public ActionResult menu() { XmlDocument doc = new XmlDocument(); int id = Convert.ToInt32(User.Identity.Name); string path = Server.MapPath("~/XMLFiles/xxxx.xml"); doc.Load(path); menu me = new menu(); me.Module = new List(); XmlNodeList xnList = doc.SelectNodes("/Modules/Module"); // List lststr = new List(); foreach (XmlNode xn in xnList) { Module md = new Module(); md.name = xn.Attributes["name"].InnerText; md.form = new List(); XmlNodeList nodes = xn.ChildNodes; foreach (XmlNode node in nodes) { string access; Form formo = new Form(); formo.form1 = new List(); XmlNodeList formnodes = node.ChildNodes; if (formnodes.Count > 0) { foreach (XmlNode formnode in formnodes) { Form1 formn = new Form1(); access = formnode.Attributes["access"].InnerText; if (access == "true" || access == "True") { formn.name = formnode.Attributes["name"].InnerText; formn.link = formnode.Attributes["link"].InnerText; formo.form1.Add(formn); } } } access=node.Attributes["access"].InnerText; if ( access== "true" || access=="True") { formo.name = node.Attributes["name"].InnerText; formo.link = node.Attributes["link"].InnerText; md.form.Add(formo); } //string lastName = xn["LastName"].InnerText; } me.Module.Add(md); } return PartialView("_Menu", me); } Create menu particle view.....@foreach (var module in Model.Module)
{
if (module.form.Count > 0)
{
@foreach (var form in module.form)
{
@if (form.form1.Count > 0)
{
@foreach (var formn in form.form1)
{
}
}
}
}
}
Vijay96 pointsPosted Jul 15, 2015, 8:27 PM EDT
1 short reply
Surendra KandiraRank #3,063 · 462 pointsPosted Oct 1, 2015, 5:47 AM EDT