With RazorViewEngine, I can do this:
if (somecondition) { <div> some stuff </div> }
but I can't seem to do this (Razor gets confused):
if (somecondition) { <div> } if (someothercondition) { </div> }
I have a situation in which I need to put my opening and closing html tags in different code blocks - how can I do this in Razor?
What Is a Void Element? The void elements or singleton tags in HTML don't require a closing tag to be valid. These elements are usually ones that either stand alone on the page or where the end of their contents is obvious from the context of the page itself.
In the left pane of the code view you can see there <> highlight invalid code button, click this button and you will notice the unclosed div highlighted and then close your unclosed div. Press F5 to refresh the page to see that any other unclosed div are there.
If you don't add a closing tag the browser won't know where it ends. It will take the next tag and think it belongs to the previous tag without the closing tag.
Razor is a markup syntax for embedding . NET based code into webpages. The Razor syntax consists of Razor markup, C#, and HTML. Files containing Razor generally have a . cshtml file extension.
Try like this:
if (somecondition) { @:<div> }
To explain Darin's answer, i.e prefixing the HTML like this:
@:<html>
@: in Razor means 'render something as plain text'
or you can use this, which outputs the HTML as you orginally wrote it (this can also be used to avoid the automatic HTML encoding that Razor does if you're trying to output HTML):
@Html.Raw("<html>")
(Html.Raw reference from MS - http://msdn.microsoft.com/en-us/library/gg568896(v=vs.111).aspx)
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