IT Man
IT Man

Reputation: 1036

ASP.MVC change _Layout elements from controller or view level

I have shared _Layout that has partial menu and body (RenderBody). I would like to control on controller or view level how _Layout is rendered. For one controller action or view i would like to hide menu (part of _Layout), for other i would like to show it.

Is there any explicit solution to do that? Something like:

thisView.Layout.HideMenu = true

Upvotes: 0

Views: 865

Answers (1)

J86
J86

Reputation: 15237

You can create a base ViewModel with a boolean property bool showMenu {get; set;} then make your other ViewModels inherit from the base ViewModel.

Finally, in your _Layout.cshtml (which will take the base ViewModel as its @model) you can do a Razor if(Model.showMenu). When true, your menu will render, when false, it'll be hidden.

Upvotes: 1

Related Questions