Dynamic ASP.NET MVC menu

Asked

Viewed 197 times

0

I am new in MVC and need to make a dynamic menu, but I do not find solution (web Forms was easier rs). I have 3 models (Menu, Submenu1 and Submenu2) I need to go through these objects and mount the html in the view, but the typed view only accepts one object and even if I do with Viewbag does not work because I have to go through Submenu1 with the Menu id and Submenu2 with Submenu1 id, with webform I went through the objects and played in a stringbuilder and then in ASPX I played the stringbuilder on a label, but with mvc I’m a little lost, someone has idea of how to do it in mvc?

1 answer

0


I found a solution as follows:

I read my objects with foreach and I was assembling the menu html in a Stringbuilder, I switched to Stringbuilder for a viewbag. In the view I read the viewbag like this: @Mvchtmlstring.Create(Viewbag.Menu) and it worked!

  • From what I understand, the object Menu should be the father of SubMenu1 and SubMenu2. I believe that maybe this is not yet the best approach, but this is on your own. If the object Menu is the parent objetop, can pass it to the view as the default type, and access submenus as properties of that object.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.