条件ASP.NET MVC剃刀部分

Ber*_*ron 23 asp.net-mvc razor asp.net-mvc-3

我想仅在某些property(Model.ReadOnly)是的时候定义此部分false.

@section toolbar {
    <div class="tool">
        <div class="row">
            @Html.ActionLink( Resources.Strings.Edit, "Edit", "Profile" )
        </div>
        <div class="row">
            @Html.ActionLink( Resources.Strings.Delete, "Delete", "Profile" )
        </div>
    </div >
}
Run Code Online (Sandbox Code Playgroud)

我试着把它包起来,@if ( !Model.ReadOnly ) {}但它不起作用.

有没有办法做到这一点?


我不想定义一个空的部分(如@itsmatt建议的那样),我的页面布局会改变是否定义了部分(使用IsSectionDefined( "toolbar" )).

Cha*_*ino 41

这应该工作.

@if (!Model.ReadOnly)
{
    <text>
    @section toolbar {

    }
    </text>
}
Run Code Online (Sandbox Code Playgroud)

我从来没说过会很漂亮;-)