开发者

MVC3 Razor and simulating same-page sections

开发者 https://www.devze.com 2023-04-12 05:26 出处:网络
Razor doesn\'t support same-page sections, so I can\'t do something like this: @if (wrapSection) { <div class=\"section-wrapped-in-div\">

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

精彩评论

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