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.
精彩评论