James
James

Reputation: 2999

ASP.Net MVC3: Hide item from _Layout file only in one view

In my layout file, I am displaying some text, and I want to hide this text only in one view. How do I tell what view is currently loaded from inside the view?

Upvotes: 0

Views: 760

Answers (2)

AndrewBoudreau
AndrewBoudreau

Reputation: 128

An easy way is to add some conditional logic to render in your _Layout as long as a viewbag bit is not set. If you don't want to render simply say so by defining the viewbag variable in the controller action and the layout won't render it.

There are more elegant solution involving attributes but this should get you going.

Don't forget the layout shouldn't know about specifically what view you're rendering thats a bleeding concerns. Viewbag helps by providing a communication and allowing decoupling of these two pieces.

Upvotes: 3

Imran Rashid
Imran Rashid

Reputation: 3502

You can set Id to that text container and in that specific view you can hide that Id by jquery
write this code in that view where you can to hide the text

$(function() { $("#id").hide(); }

Upvotes: 2

Related Questions