公告
财富商城
积分规则
提问
发文
2019-06-15 06:42发布
看我几分像从前
With Razor, how do you conditionally quit or end 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:
return
@if (Model != null) { @Html.Partial("somePartial", Model) }
or if you use RenderPartial:
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 }
最多设置5个标签!
No, you don't
return
in a view, you simply don't include such partial in the main view:or if you use
RenderPartial
:Invert the if: