KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I just started using Razor instead of the WebForms-ViewEngine. Now in my Razor-View i have something like this: @{ int i = 42; string text; if (i == 42) { text = "i is 42!"; } else //i is not 42 //<- Error here { text = "i is something else"; } } I get a warning and at runtime it get an exception in the else line: Expected a "{" but found a "/". Block statements must be enclosed in "{" and "}". You cannot use single-statement control-flow statements in CSHTML pages. Apparently the compiler doesn't like comments between the else and the {. I also tried commenting with @* and /*, which gave similar error-messages. Is there anyway to make a comment in razor like I want it? Disclaimer: Yes i know i could fix it simply like this: @{ int i = 42; string text; if (i == 42) { text = "i is 42!"; } else { //i is not 42 text = "i is something else"; } } However it doesn't fit our coding guidelines and having the comment on the same line makes my intentions more clear.
Tags (comma-separated)
Save Edits
Cancel