Is recursive rendering of a partial view in Asp.Net Mvc a bad idea?

I want to display a menu structure that will look like

<ul>
   <li>
      MenuItemName1
      <ul>
        <li>Child Item</li>
      </ul>
   </li>
   <li>
      MenuItemName2
   </li>
</ul>

I have a menuitem class that contains menu, name, url and children menu items. I would like to create a partial view that displays each item as an unordered list, as mentioned above, and I would call it recursively to go through the whole tree.

It is a bad idea? Will it be very slow?

+3
source share
3 answers

I do this and it does not look particularly slow, but it is not a site with a large volume. It would be a great place to post in caching.

. , HTMLHelper , .

+3

.

, .

0

I'm not sure about MVC, but with traditional ASP.Net 2.0, if you injected user controls too deeply, you could explode the stack. I saw it happen once at about 10+ nesting levels.

0
source

Source: https://habr.com/ru/post/1710824/


All Articles