0

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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

i mean, or you could just use MVC to solve an MVC concern, just saying.
2

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(); }

3 Comments

This doesn't seem to be working, I think the partial is loaded after the javascript is called
This will be called when you partial view is loaded please make sure that you are rendering this view after your text in layout and you have added jquery!
Although it will be hidden from view, this still will send the text to the browser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.