I want to bind my menu's retrieved from my LINQ query to menus in Layout.
In Asp.net whenever i had such requirement i use to write dynamic menu binding code in load event of masterpage.
In mvc i understand that the request first goes to controller and then Appropriate view is loaded but In my case there are two pages which i need to load
1. Layout page(Master Page) with Appropriate Menus
2. Child page.(Which has any basic features.)
Here i am not able to understand which code to write where.
Example
1. where to write code for loading menu in Layout page?
2. How to call code for loading menu?
3. When to call code for Loading menu of Layout page and when & where to call my actual child page Action?
What I have tried:
public JsonResult GetMenu()
{
int LevelId = 1;
GEContext gc = new GEContext();
List<Menu> menuList = gc.Menus.Include("MenuRights").ToList();
var pageObject = (from op in gc.Menus
join mr in gc.MenuRights on op.MenuId equals mr.MenuId
where mr.LevelId == LevelId
select new { op });
return Json(pageObject, JsonRequestBehavior.AllowGet);
}
public class Menu
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int MenuId { get; set; }
[StringLength(20)]
public string MenuName { get; set; }
[StringLength(50)]
public string ActionName { get; set; }
[StringLength(50)]
public string ControllerName { get; set; }
[StringLength(200)]
public string MenuUrl { get; set; }
public int ParentId { get; set; }
[StringLength(10)]
public string TargetWindow { get; set; }
[StringLength(20)]
public string ProjectCode { get; set; }
[ForeignKey("ProjectCode")]
public Project Project { get; set; }
}
public class MenuRights
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int MenuRightsId { get; set; }
public int MenuId { get; set; }
public int LevelId { get; set; }
[ForeignKey("LevelId")]
public Level Level { get; set; }
[ForeignKey("MenuId")]
public Menu Menu { get; set; }
[StringLength(20)]
public string ProjectCode { get; set; }
[ForeignKey("ProjectCode")]
public Project Project { get; set; }
}