C# Razor退出代码块
我试图避免更多的筑巢。 有没有办法退出Razor中C# Razor退出代码块,c#,asp.net,asp.net-mvc,razor,C#,Asp.net,Asp.net Mvc,Razor,我试图避免更多的筑巢。 有没有办法退出Razor中@{//code}块的末尾? 我尝试了下面的示例,但它忽略了视图的其余部分 @{ if(Model.Products.Count == 0) { <p>No products were found</p> return; } // display products } // I want to return to here // Rest of the view @{ 如果(Mode
@{//code}
块的末尾?
我尝试了下面的示例,但它忽略了视图的其余部分
@{
if(Model.Products.Count == 0)
{
<p>No products were found</p>
return;
}
// display products
} // I want to return to here
// Rest of the view
@{
如果(Model.Products.Count==0)
{
没有发现任何产品
返回;
}
//展示产品
}//我想回到这里
//其余部分
您可以使用
@helper DisplayProducts()
{
如果(Model.Products.Count==0)
{
没有发现任何产品
返回;
}
//展示产品
}
@显示产品()
//其余部分
如果我正确理解问题,您可以删除return
并将产品显示代码放在else
块中。我知道,这就是我现在正在做的,但我正在尽可能避免嵌套。
@helper DisplayProducts()
{
if(Model.Products.Count == 0)
{
<p>No products were found</p>
return;
}
// display products
}
@DisplayProducts()
//Rest of the view