我可以在Razor的共享模板中使用@section吗?

时间:2017-03-29 07:06:51

标签: asp.net-mvc razor

我在共享模板中使用@section { ... }表达式。由于我没有看到该部分中呈现的共享代码,并且由于我在互联网上找不到提示,因此我不确定这是否应该起作用。

以下是我的检查方法:

_Shared.cshtml:
...
<div class="not-in-section">
    Not in section
</div>

@section Templates {

<div class="in-section">
    in section
</div> 
...

我看到了部分渲染的部分,但没有看到部分代码。

在index.cshtml中,我这样调用:

...
@Html.Partial("~/Views/Shared/_Shared.cshtml")
...
@section Templates {

    <script type="x-template" id="book-template">
...

所以我调用_Shared.cshtml并引用@section,它可以正常工作。

有人可以确认这应该有效吗,或者这将永远不会有效?如果它应该工作,应该改变什么?

0 个答案:

没有答案
相关问题