2011-04-26 88 views

回答

2

如果你可以使用JavaScript/jQuery的,你可以有这个视图

$("#divInMasterpage").hide(); 

当页面呈现时,它会隐藏母版页中的div。

0

加载网页时,所有母版页的xHtml及其内容页的xHtml都合并为一页。

因此,只要存在于页面内,您就可以按常规方式隐藏任何潜水。

$("#YourDiv").hide(); 

或者

$("#YourDiv").css('visibility', 'hidden'); 
0

如果你正在寻找一个MVC 3类型的答案,而不是JavaScript中,你可以设置一些ViewBag属性,然后在您的视图测试它。

在母版页(剃刀语法):

@* 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> 
} 

如果可以显示DIV,那么javascript例子都去,因为他们允许进行切换知名度的方式。但是,如果您确定某个给定div应该隐藏在给定视图中,则此方法更好,因为它不会发送永远不需要的HTML和Javascript。