Zet Zet - 2 years ago 118
HTML Question

how to change navigation bar in .Net MVC

I would like to change navigation bar in my application depending on who is loged in. I don't want customer to see links available to admin for example. From information that I've found so far I think I will have to create couple of versions of layout and use wright one with appropriate view. If I'm wrong what is the best way to do it?

Answer Source

In most Web applications administration area is quite different from "operational" area (that dedicated to normal users). Providing more details might be useful, but I recommend to use areas, a feature of MVC:

  • they allow to have a clear separation by semantics of content. In your case this means administration vs. other parts of the application

  • each area can define a default layout (or other layout pages) to be used in that particular area

  • areas act as containers for security and routes

Using the same layout between administrative and other part of your application might force into ugly code like the following:

if (@Model.IsAdmin)
    // show admin link 1 here

// normal user or public content here

if (@Model.IsAdmin)
    // other code accessible for admin only

So, shortly put, I advice for separation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download