1
我目前有一個導航欄,它是從MS SQL數據庫動態創建的,但我想添加第二個子圖層。以下是我目前使用的單層導航欄。MVC 5動態導航欄2層
導航
public partial class Navigation
{
public int Id { get; set; }
public string Title { get; set; }
public Nullable<int> Position { get; set; }
public bool Main { get; set; }
public string Action { get; set; }
public string Controller { get; set; }
}
的HomeController
[ChildActionOnly]
public ActionResult Navigation()
{
var navigationModel = (from m in db.Navigations where (m.Main == true) orderby m.Position select m);
return View(navigationModel);
}
導航
@{ Layout = null; }
@model IEnumerable<WebApplication1.Models.Navigation>
<ul class="nav sf-menu clearfix">
@foreach (var item in Model)
{
@Html.MenuLink(item.Title, item.Action, item.Controller)
}
</ul>
第二層NEE ds鏈接到內容表,關係是db.Navigations.Id = db.Contents.NavigationId。
內容
public partial class Content
{
public int Id { get; set; }
public Nullable<int> NavigationId { get; set; }
public string Title { get; set; }
public string Content1 { get; set; }
public Nullable<int> Position { get; set; }
public string Image { get; set; }
public string Sub { get; set; }
public Nullable<bool> Active { get; set; }
public string Url { get; set; }
public string Summary { get; set; }
}
可能有人請提供我怎麼能子數據綁定到父數據集,然後在查看教程或示例代碼,如何檢查,如果父母擁有孩子的記錄和如果這樣循環通過它們。
任何幫助,將不勝感激:-)