I am trying to do this using Razor templating:
@if(isNew)
{
}
...
@if(isNew)
{
}
The error is:<
Razor doesn't like it when you split start/end tags up like this as it can't parse the HTML properly, so you have to escape them as plain text:
@if(isNew)
{
@:
}
...
@if(isNew)
{
@:
}
The more conventional approach would be to repeat the markup inside the div (using partials or otherwise) - which approach is more desirable, I would say, is dependent upon the nature of the markup in between the conditional divs:
@if(isNew)
{
}
else
{
}
I would prefer this approach if either:
I should also add the option of using helper methods:
@helper MainMarkup()
{
}
@if(isNew)
{
@MainMarkup()
}
else
{
@MainMarkup()
}
This is useful if you want to use the second option above but avoid repeating markup or nesting too many partials (particularly if this markup is only relevant for this view).