c# - How do I configure one menu per area in .Net MVC and other area-specific variables for the layout -



c# - How do I configure one menu per area in .Net MVC and other area-specific variables for the layout -

i'm working on rather big application in .net mvc 4, have 1 master menu navigate through areas , 1 submenu navigate through components of 1 area.

obviously submenu different per area, , i've "solved" using viewbag.

i have 1 master controller abstract methods:

public abstract class basecontroller: controller { protected abstract string getmenu(); protected override sealed void onresultexecuting(resultexecutingcontext filtercontext) { viewbag.menu = getmenu(); base.onresultexecuting(filtercontext); } }

and every area has basecontroller next declaration

public abstract class area1controller: basecontroller { protected string getmenu() { homecoming "menunameforarea1"; } }

and in _layout, access menu this:

@{ var menu = viewbag.menu string; if (menu != null) { html.renderpartial(menu); } }

the problem there quite variables joining handbag of "things need displayed on _layout page different per area".

so wonder best solution tackle problem. create viewmodel _layout page? set viewmodel in viewbag or forcefulness every viewmodel inherit base of operations viewmodel?

since every area has separate _viewstart, had thought of using sections tackle in type-safe way, unfortunately can't seem define sections in _viewstart.

suggestions welcome.

bonus question: solution to:

show active area in main menu (configured 1 time per area) show active item in submenu (configured 1 time per controller should overridable specific)

c# razor asp.net-mvc-4 asp.net-mvc-areas

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -