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