我是一名初學者,我想在左側顯示菜單,如This Website,當用戶單擊任何類別名稱或其子類別名稱時,我想顯示與此相關的產品點擊類別。Asp.Net中的數據庫動態菜單MVC
我在我的數據庫中創建了4個表格。
類別
類別ID(PK),類別名稱,描述,圖標
子類別
SubCategoryId(PK),SubCategoryName,描述,圖標,類別ID(FK)
SubSubCategory
SubSubCategoryId(PK),SubSubCategoryName,描述,圖標,SubCategoryId(FK)
產品
產品編號(PK),名稱,價格,描述,類別編號(FK),SubCategoryId(FK),SubSubCategoryId(FK )
Category.cs模型
public partial class Category
{
public Category()
{
Products = new HashSet<Product>();
SubCategories = new HashSet<SubCategory>();
}
public int CategoryId { get; set; }
public string CategoryName { get; set; }
public string Description { get; set; }
public string Icon{ get; set; }
public virtual ICollection<Product> Products { get; set; }
public virtual ICollection<SubCategory> SubCategories { get; set; }
}
子Category.cs
public partial class SubCategory
{
public SubCategory()
{
Products = new HashSet<Product>();
SubSubCategories = new HashSet<SubSubCategory>();
}
[Key]
public int SubCategoryId { get; set; }
public string SubCategoryName { get; set; }
public int? CategoryId { get; set; }
public string Description { get; set; }
public string Icon{ get; set; }
public virtual Category Category { get; set; }
public virtual ICollection<Product> Products { get; set; }
public virtual ICollection<SubSubCategory> SubSubCategories { get; set; }
}
SubSubCategory.cs
public partial class SubSubCategory
{
public SubSubCategory()
{
Products = new HashSet<Product>();
}
[Key]
public int SubSubCategoryId { get; set; }
public string SubSubCategoryName { get; set; }
public int? SubCategoryId { get; set; }
public string Description { get; set; }
public string Image { get; set; }
public virtual ICollection<Product> Products { get; set; }
public virtual SubCategory SubCategory { get; set; }
}
Product.cs
public partial class Product
{
public int ProductId { get; set; }
public int? CategoryId { get; set; }
public int? SubCategoryId { get; set; }
public int? SubSubCategoryId { get; set; }
public string Name { get; set; }
[AllowHtml]
public string Description { get; set; }
public decimal? Price { get; set; }
}
並且控制器和視圖在哪裏?你做了什麼? – lyz
你應該先對自己的各種教程網站進行一些研究,然後自己嘗試一下。如果事情仍然沒有按照他們的想法工作,那就發佈一個問題。這看起來像你不想嘗試,並希望我們爲你做! –
我搜索了這個,他們只在教程中使用了1個表格。像菜單表只有MenuId,MenuName,Url,ParentId。但我有3個菜單表 –