开发者

MVC3 Razor and simulating same-page sections

Razor doesn't support same-page sections, so I can't do something like this:

@if (wrapSection)
{
    <div class="section-wrapped-in-div">
        @RenderSection("mySection")
    </div>
}
else
{
    @RenderSection("mySection")
}

@section mySection
{
    some stuff here...
}

I know I can accomplish this with a partial view, but this is specific to this page, and really would be best kept on the same pag开发者_运维技巧e.

Is something like this possible?


You should make a helper method:

@helper MySection(...) {
    ...
}

@MySection(...)

Unlike sections, helpers can also take parameters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜