ASP.NET MVC – Database Driven Menu -
I have a database menu structure that I would like to add to the site.master file.
I have seen other questions on stack overflow but can not get it to work on my website.
How do I add user controls to the site? Master file?
Menu> Scans
(MainMenuSort mainMenuSort (list ) ViewData ["MainMenuSortListDisplay"]) {%> ; & Lt; Li & gt; & Lt;% = Html.Encode (Main menu suit.manmenui.man menu)% & gt; & Lt; / Li & gt; & Lt;% foreach (SubMenuSort subMenuSort in the list (SubmenuSort & gt;) ViewData ["SubMenuSortListDisplay"]) {%> & Lt;% if (Main Menu Suit.ManManIID.ID == SubmenuArt.SSBMEIID.MainMenu.id) {%> & Lt; Li & gt; & Amp; Lt;% = Html.Encode (submenu asert. Sbm menu id.menuenu name)% & gt; & Lt; / Li & gt; & Lt;%}% & gt; & Lt;%}% & gt; & Lt;%}% & gt;
You must use HTML renderer method in your master page.
Anything that you are taking to the scene using your master page, you have to set the MainmenourcelistDisplay and Submenu Extracted Downloaded Data Keys.
Use it in its owner
& lt;% HTML.RenderPartial ("~ / visible / share / menu.skux"); The path must be an app relative path for the control folder. Typically they go under the share, you can create this structure, how you want to be under the shared folder.
To strengthen this technique, use a strongly typed partial question, you will probably earn as a new class (menu model) with two common collections and it will be appended to the model folder of the application Will keep in After this, the method in the constructor calls a method that populates the lists.
Public class menu model {public inenemable & lt; Main menu source & gt; External list {receive; Set;} Public IEnumerable & lt; SubMEnuSort & gt; {Receive InternalList; Set;} public menu model () {VoidThatFillsTheInnerAndOuterList (); } This means that you can do it in your controller
public performance ShowAForm {ViewData ["MenuPartialData"] = New Menu Model (); See Return (); } After setting this key, your master page can use the overload of RenderPartial, such as
HTML. RenderPartial ("~ / View / Share / Menu .ascx", (menu model) View Data ["Manuproved Data Data"]); & Gt%; Believes that your partial menu model is typed in the class. Then partly you can use the model that rewrites your code a bit
& Lt; Li & gt; & Lt;% = Html.Encode (Main menu suit.manmenui.man menu)% & gt; & Lt; / Li & gt; & Lt;% foreach (Submenuort submenuort in Model.InnerList) {%> & Lt;% if (Main Menu Suit.ManManIID.ID == SubmenuArt.SSBMEIID.MainMenu.id) {%> & Lt; Li & gt; & Amp; Lt;% = Html.Encode (submenu asert. Sbm menu id.menuenu name)% & gt; & Lt; / Li & gt; & Lt;%}% & gt; & Lt;%}% & gt; & Lt;%}% & gt; Hopes
Comments
Post a Comment