Reputation: 1
How to hide a div in the Masterpage from a View
Upvotes: 0
Views: 2476
Reputation: 11763
If you're looking for an MVC 3 type answer instead of javascript, you could set some ViewBag property and then test for it in your view.
In the master page (Razor syntax):
@* null test allows you to omit the ViewBag.ShowThisDiv in most views.*@
@* Your div will display if ViewBag.ShowThisDiv is true or not included. *@
@* Set ViewBag.ShowThisDiv == false in the controller for the hiding view. *@
@* Note: Razor syntax requires that you wrap the conditional div in <text> tags *@
@* or prefix that line with @: *@
@if (ViewBag.ShowThisDiv == null || ViewBag.ShowThisDiv == true) {
<text><div>Your conditional content here</div></text>
}
If you may show the div, then the Javascript examples are the way to go as they allow for visibility to be toggled. However, if you know for sure that a given div should be hidden in a given view, then this method is better as it won't send HTML and Javascript that will never be needed.
Upvotes: 0
Reputation: 5968
When a web page is loaded all of the master page's xHtml and its content page's xHtml are merged together as one page.
So you can hide any dive the usual way as long as it exists within the page.
$("#YourDiv").hide();
Or
$("#YourDiv").css('visibility', 'hidden');
Upvotes: 0
Reputation: 109027
If you can use javascript/jquery, You can have this in the view
$("#divInMasterpage").hide();
and when the page renders, it will hide the div in master page.
Upvotes: 2