Home Recursion in a table using razor in ASP.NET Core
Reply: 0

Recursion in a table using razor in ASP.NET Core

user1143 Published in March 19, 2018, 4:23 pm

I have this product category model:

public class ProductCategory
    public int Id { get; set; }
    public int? ParentId { get; set; }
    public string Title { get; set; }

Using the parent Id, I want to display a list of categories and sub-categories (max three levels) in a tabeled list, like so:

    <tr><td colspan="3">Category #1</td></tr>
    <tr><td></td><td>Category #1.1</td><td></td></tr>
    <tr><td></td><td>Category #1.2</td><td></td></tr>
    <tr><td colspan="2"></td><td>Category #1.2.1</td></tr>
    <tr><td colspan="2"></td><td>Category #1.2.2</td></tr>
    <tr><td colspan="3">Category #2</td></tr>

I tried to implement this solution, but I don't understand how I'm supposed to pass the data to the partial view. And my categories don't have a reference to children, but rather to parents.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.371369 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO