将 @section 放入 @if .net mvc 3
我似乎无法让它发挥作用。
@if (isReal)
{
@section Navigation{
@{Html.RenderPartial("NavigationForInput");}
}
}
这不起作用,因为它说“一旦在代码中,你就不需要@ blah blah blah”,
但是,当我从节前面删除@时,它想使用节作为类型变量。
我怎样才能有条件地显示该部分?
I can not seem to get this to work.
@if (isReal)
{
@section Navigation{
@{Html.RenderPartial("NavigationForInput");}
}
}
that doesn't work because it says "once inside code you dont' need @ blah blah blah"
but, when I remove the @ from in front of section, it wants to use section as a type variable.
how can I only show that section conditionally?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据您的布局是否有未定义部分的替代方案,您可以反转
@if
和@section
如果您只想省略导航,这应该是很好,但如果您在布局中使用 IsSectionDefined("Navigation") ,它将不起作用,因为它始终返回 true。
Depending if your Layout has an alternative for undefined sections or not, you could just reverse the
@if
and@section
If you just want to leave out the nav, this should be fine, but it won't work if you are using IsSectionDefined("Navigation") in your layout, as it will always return true.
想法:
这是代码:
快乐编码!
The idea:
Here is the code:
Happy coding!
该
构造用于定义节。要渲染某个部分,请使用
RenderSection ()
方法。The
construct is used for defining a section. To render a section you use the
RenderSection()
method.