Reputation: 133
I'm trying to avoid more nesting.
Is there any way to exit to the end of a @{ //code }
block in Razor?
I tried the example below, but it simply ignores the rest of the view then.
@{
if(Model.Products.Count == 0)
{
<p>No products were found</p>
return;
}
// display products
} // I want to return to here
// Rest of the view
Upvotes: 3
Views: 2201
Reputation: 7150
You can use @helper
@helper DisplayProducts()
{
if(Model.Products.Count == 0)
{
<p>No products were found</p>
return;
}
// display products
}
@DisplayProducts()
//Rest of the view
Upvotes: 4