score:2
Here is an aproximation with a recursive solution:
In your view:
@WriteChilds(null, "")
And this the method body, I'm sure you can translate Console.WriteLine to html output:
public void WriteChilds(int? ParentCategoryId, string parentName) {
var categories = Model.Where(a => a.parentCategoryId == ParentCategoryId);
foreach(var category in categories) {
Console.WriteLine(parentName + " " + category.CategoryName);
WriteChilds(category.CategoryId, category.CategoryName);
}
}
Source: stackoverflow.com
Related Query
- How to code a Foreach Loop for Endless Categories Tree in MVC.Net?
- ForEach loop with Lambda expression in Razor code MVC 5 For List<T>
- foreach loop is displaying the same image for all posts in mvc view
- how to replace foreach loop with for loop
- C# LINQ or for loop How to get a data source from a db?
- how to fetch data from database using linq query for relationship 1:N and N:N (between 3 entity) in asp.net mvc EF code first?
- How to store join query data and retrieve using foreach loop from master layout page in asp.net mvc
- How to convert the following foreach loop to linq code format?
- How to build a dynamic AND OR linq expression tree in a loop
- How to get Resharper to convert back to a foreach loop
- How do I segment the elements iterated over in a foreach loop
- How to reuse a linq expression for 'Where' when using multiple source tables
- How to check for the presence of an OrderBy in a ObjectQuery<T> expression tree
- linq - how do you do a query for items in one query source that are not in another one?
- LINQ: How to Use RemoveAll without using For loop with Array
- Avoid extra loop and could not find implementation of query pattern for source type int Select not found
- How to convert this foreach loop into Linq code?
- How do I convert this double foreach loop to just lambdas?
- How to avoid loop by using LINQ for the following code?
- How to convert foreach loop to a Linq query?
- Local variable is never used warning for foreach loop
- C# - How to transform a For loop into a Linq expression?
- Convert a for loop nested in a ForEach loop to LINQ
- convert foreach loop to linq code
- How to convert Foreach loop to Linq (in datagridview)
- How to query ManagementObjectCollection with LINQ, then loop through PropertyData for returned ManagementObject?
- How to unpack an expression tree and check for null values
- How to implement nested for loop into Linq?
- linq for a for loop inside a foreach loop
- Optimize solution for categories tree search
More Query from same tag
- A circular reference was detected while serializing an object of type... How to solve this?
- Are we compromising performance for achieving code readability when using LINQ?
- Does adding .ToArray or .ToList always make database queries faster?
- {"Invalid object name 'ICCSS.mdf.TblCustomers'."}
- Entity Framework Dynamic Query Expression being ignored
- Linq to Mongodb dynamic update function
- Need help with formulating LINQ query
- Case insensitive string compare in LINQ-to-SQL
- Use Linq query to compare date only with DateTime field
- MVC EF - Inner Join
- How to properly union different IQueryables and then serialize them in JSON
- Getting Attribute Inside Linq "Where" using string
- Locate nested property with Linq?
- linq where -> compare to list of longs
- C# Remove object from list stored in an ASP session
- Is order of the predicate important when using LINQ?
- Dropdown does not display data on View MVC
- How do I preserve whitespace characters when parsing XML from C# LINQ
- How to set a DB value to Nothing with Linq?
- == by default is case insensitive in c# linq
- Want to read only one document
- Linq replace null/empty value with another value
- Sort C# map with value and key
- How to search keywords using "And" clause in database : LINQToSQL
- Linq query - ON clause of inner join cannot compare two Guids
- Can't get the children of root element in xml file
- Find all pairs of intersecting rectangles with linq
- List Operations without ForLoops
- "An expression tree may not contain an assignment operator" using Aggregate in a Select clause
- Find first index for value in List