在 ASP.NET MVC2 中将数据从视图传递到母版页的简洁方法(从视图设置 css 类)
我有一个带有母版页的 ASP.NET MVC2 应用程序。母版页呈现站点布局 div 如下:
<div id="wrapper">
<div id="column1">
{contentplaceholder}
</div>
<div id="column2">
{contentplaceholder}
</div>
</div>
在我的视图中,我想将类名应用于包装 div,因此在查看主页时,包装 div 将是:
<div id="wrapper" class="homepage">
</div>
或者在联系页面上,
<div id="wrapper" class="contact">
</div>
理想情况下我会喜欢在视图 aspx 页面中设置此变量,而不是在控制器操作中。实现这一目标的最干净的方法是什么?我正在思考以下内容:
在母版页中:
<div id="wrapper" class="<%=WRAPPER_CLASS%>">
</div>
然后在视图中:(
<% WRAPPER_CLASS = "contact"; %>
显然上面的示例不起作用,但是有人有什么好的想法吗?)
I have a ASP.NET MVC2 application with a master page. The master page renders the site layout divs as follows:
<div id="wrapper">
<div id="column1">
{contentplaceholder}
</div>
<div id="column2">
{contentplaceholder}
</div>
</div>
In my View, I would like to apply a classname to the wrapper div, so when viewing the homepage, the wrapper div would be:
<div id="wrapper" class="homepage">
</div>
or on the contact page it would be
<div id="wrapper" class="contact">
</div>
Ideally I would like to set this variable in the view aspx page, rather than in a controller action. What would be the cleanest way to achieve this? I was thinking something along the lines of:
In Master page:
<div id="wrapper" class="<%=WRAPPER_CLASS%>">
</div>
and then in View:
<% WRAPPER_CLASS = "contact"; %>
(obviously the above example doesn't work, but does anyone have any good ideas?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这个
为什么不在母版页和 aspx 视图中
Why not try this, within the master page:
and in the aspx view