【发布时间】:2014-03-24 06:25:38
【问题描述】:
我的模型如下:
public class Category
{
[Key]
public int Id { get; set; }
[StringLength(200), Required, DataType(DataType.Text)]
public string Title { get; set; }
[Display(Name = "Parent Category")]
public int? ParentId { get; set; }
[DisplayFormat(NullDisplayText = "Root")]
public virtual Category ParentCategory { get; set; }
public virtual ICollection<Category> ChildCategories { get; set; }
}
本质上是分层的,“ParentId”引用“Id”作为自引用。有了这个,我试图按如下方式显示数据:
+--------+-----------------+
| S. No | Name |
+--------+-----------------+
| 1 | Parent One |
+--------+-----------------+
| 1.1 | Child-1 of One |
+--------+-----------------+
| 1.2 | Child-2 of One |
+--------+-----------------+
| 2 | Parent Two |
+--------+-----------------+
| 2.1 | Child-1 of Two |
+--------+-----------------+
| 3 | Parent Three |
+--------+-----------------+
请帮帮我。
【问题讨论】:
标签: asp.net-mvc-3 model views hierarchy