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 Articles
- How to code a Foreach Loop for Endless Categories Tree in MVC.Net?
- convert foreach loop to linq code
- Converting foreach loop to LINQ query breaks code
- ForEach loop with Lambda expression in Razor code MVC 5 For List<T>
- C# LINQ Find List Inside Another List, Better way to code this than a foreach loop
- Convert the code from Foreach loop to Linq
- How to convert the following foreach loop to linq code format?
- Multi-line foreach loop in linq / lambda
- Linq query built in foreach loop always takes parameter value from last iteration
- Replace foreach loop with linq
- EF - Update multiple rows in database without using foreach loop
- How to build a dynamic AND OR linq expression tree in a loop
- foreach loop vs. ForEach method - Differences?
- How to get Resharper to convert back to a foreach loop
- How do I segment the elements iterated over in a foreach loop
- Simplifying a foreach loop with LINQ (selecting two objects in each iteration)
- Using LINQ in foreach loop declaration
- LINQ Source Code Available
- Linq + foreach loop optimization
- Populating List<T> within a foreach loop after pattern matching
- Use Linq to flatten a nested list instead of a foreach loop
- need help converting C# foreach loop to lambda
- Infinite IEnumerable in a foreach loop
- Trouble with using predicatebuilder in a foreach loop
- Faster data checking and updating inside foreach loop
- .NET 4 Code Contracts: "requires unproven: source != null"
- Simplify conventional foreach nested loop using linq & lambda expression
- Updating single Column of List without Foreach Loop
- Enumerator stuck in endless loop when removing excess items from a List
- C# Format foreach loop as Lambda
- get Ident_Current from Linq
- Using a Singleton pattern to Linq to Sql Data Context
- Linq TakeWhile depending on sum (or aggregate) of elements
- Linq filter using List<int>
- Function to calculate Weighted Average by two keys is elusive
- XDocument XElement.Descendants issue
- Linq to SQL order by with Distinct
- How to Remove specific field from List of models
- Why am I getting "Collection was modified; enumeration operation may not execute" when not modifying the enumerated collection?
- Get implemented types of generic interface
- Why can't I assign the return of a LINQ Find() or FirstOrDefault() result?
- How to write a LINQ query if index usage is necessary?
- LINQ - How to read ID which is Autonumber after submitting the data
- NHibernate collection size without loading the entire collection
- How to fix the following code so that it is ordered?
- How to get MAX value from Dictionary?
- LINQ syntax question
- Set selected values in asp ListBox with one line
- Is there a way to increase performance on these two foreach loops?
- Include nested entities using LINQ