开发者

ASP.NET MVC3 Razor - How to conditionally quit or end or return or break a partial view?

开发者 https://www.devze.com 2023-02-11 10:41 出处:网络
With Razor, how do you conditionally quit or e开发者_如何学Cnd or return or break a partial view?

With Razor, how do you conditionally quit or e开发者_如何学Cnd or return or break a partial view?

@if (Model == null)
{
    return;
}


No, you don't return in a view, you simply don't include such partial in the main view:

@if (Model != null) {
    @Html.Partial("somePartial", Model)
}

or if you use RenderPartial:

@if (Model != null) {
    @{Html.RenderPartial("somePartial", Model);}
}


Invert the if:

<p>html that I always want</p>
@if (Model != null)
{
      your html when model != null
}
0

精彩评论

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