有条件的ASP.NET MVC路段剃刀 [英] Conditional ASP.NET MVC razor sections

查看:107
本文介绍了有条件的ASP.NET MVC路段剃刀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要定义此节只有当某些属性( Model.ReadOnly )是

I want to define this section only if some property (Model.ReadOnly) is 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 >
}

我想结束工作在 @if(!Model.ReadOnly){} ,但它不工作。

有没有办法做到这一点?

Is there a way to do this?

我不希望定义一个空的部分(<一个href=\"http://stackoverflow.com/questions/7097162/conditional-asp-net-mvc-razor-sections/7097248#7097248\">as @itsmatt建议),部分是否定义或没有我的页面更改的布局(使用 IsSectionDefined(工具栏))。

I do not want to define an empty section (as @itsmatt suggests), the layout of my page changes whether the section is defined or not (using IsSectionDefined( "toolbar" )).

推荐答案

这应该工作。

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

    }
    </text>
}

我从来没有说过这将是pretty; - )

I never said it would be pretty ;-)

这篇关于有条件的ASP.NET MVC路段剃刀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆