【发布时间】:2011-02-15 21:57:15
【问题描述】:
使用 Razor,您如何有条件地退出或结束或返回或中断部分视图?
@if (Model == null)
{
return;
}
【问题讨论】:
-
你已经用你的例子回答了这个问题。它是有效的并且确实有效。复制并回答:stackoverflow.com/questions/25742865/…
标签: asp.net asp.net-mvc-3 razor
使用 Razor,您如何有条件地退出或结束或返回或中断部分视图?
@if (Model == null)
{
return;
}
【问题讨论】:
标签: asp.net asp.net-mvc-3 razor
不,您不会在视图中return,您根本不会在主视图中包含这样的部分:
@if (Model != null) {
@Html.Partial("somePartial", Model)
}
或者如果你使用RenderPartial:
@if (Model != null) {
@{Html.RenderPartial("somePartial", Model);}
}
【讨论】:
反转 if:
<p>html that I always want</p>
@if (Model != null)
{
your html when model != null
}
【讨论】: