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:
@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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With