I have a category table that has three fields: Id , Title and ParentId . I would like to create a recursive hierarchical structure of my table (tree) in a cshtml file. I am new to ASP.NET MVC and I donβt know how to do this because there is no code file and I donβt know where to start. Note that I am storing a jungle , not a tree, in my database. In other words, the result tree can have many roots.
Id
Title
ParentId
The easiest is to use an assistant:
@helper RecurseSomething(MyClass data) { <li> @data.Title @if (data.SubItems.Count() > 0) { <ul> @foreach(var subData in data.SubItems) { @RecurseSomething(subData); } </ul> } </li> }
Source: https://habr.com/ru/post/891697/More articles:nodejs: Can eval js code use runInNewContext and limit its execution timeout? - node.jsGit window $ Git config --global http.proxy warning: http.proxy has several meanings - gitAsynchronous call - is EndInvoke required? - multithreadingAndroid multimedia controller displays display for a short time - androidAndroid Click LongClickListener to get X, Y, OnTouchListener coordinates - androidCan operators in Smalltalk be overloaded? - operator-overloadingError with strtotime php - phpProminent lines not detected by the Hough transform - visual-c ++How to use mysql_free_result ()? - phpCall php class method from string with parameter - phpAll Articles