I knew this, but I had a brain fart here and couldn’t figure out what was wrong. I was trying to output some simple text to the browser based on some condition:
I started to get the following error message:
The type or namespace name 'Do' could not be found (are you missing a using directive or an assembly reference?)
Along with a list of others:
But nothing really said what was wrong.
Nothing’s really wrong, per se, but Razor can’t figure out what I want to do here and doesn’t know that Do should be text and not me trying to code something. To fix it, simply wrap the text in a <span> tag and roll:
Tada! </facepalm>
The only reason I ran into this was because I copy & pasted the text. Normally you’d get IntelliSense as soon as you start typing and that should throw up a context flag pretty quick.
or wrap the text with
ReplyDeleteYou can optionally wrap nested content with a block for cases where you have content that you want to render to the client without a wrapping tag:
ReplyDelete@if(true)
{
Do something @DateTime.Now
}
Hi Henrik...I think the Blogger engine filtered out some of your text. Were you meaning to use an HTML-style text tag? The text tag is not rendered. Alternatively, you can use a @: as a line prefix to write out a line if you don't want to output the html. Cheers.
ReplyDeleteHi ChipOne
ReplyDeleteCorrect the < text > tag is missing :)
@if(true)
{
< text >
Do something @DateTime.Now
< / text >
}