I have a model like as follows:
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; }
}
Which is hierarchical in nature, 'ParentId' reference to 'Id' as self referencing. With this, I'm trying to display the Data as follows:
+--------+-----------------+
| 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 |
+--------+-----------------+
Please help me on this.