B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
which can be could news too because i got to test my custom error page (Error.cshtml).
g.
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
I think this is how razor is working currently. Look at this examples,
@if(true)
@* ... this is a Razor comment ... *@ {
}
This will show a parse error but this will not,
@if(true){
@* ... this is a Razor comment ... *@
}
The fact is that Razor expect a curly brace immediatly after the code block because
You cannot use single-statement control-flow statements in CSHTML pages.
Now look this. It will show you,
A space or line break was encountered after the "@" character. Only valid identifiers, keywords, comments,
"(" and "{" are valid at the start of a code block and they must occur immediately following "@" with no space in between.
@
@* This is a comment. *@ {
}
But this will work,
@{
@* This is a comment. *@
}
Every parser have some rules and razor have this rule.
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Every parser have some rules and razor have this rule.
Hi imran ... while that's a good point, in this case, i disagree with you.
Let me explain.
Some languages are column specific, for example RPG; for column specific languages, one
must, for example, code operands in fixed columns, operators in different fixed columns, et cetera.
OTOH, for most, if not all, other programming languages, the code space is either white space
or not white space; in such cases,
the fundamental rule of parsing is to ignore white space; FWIW, comments are usually deemed to be white space.
g.
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
BTW, imho, what makes this parsing anomaly especially toxic is that a run time exception results from it.
g.
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
hi ignat, i do not understand why you are asking this particular question. please elaborate.
thnx/rgds/gerry
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
gerrylowry
All-Star
20525 Points
5713 Posts
ASP.NET MVC 4: Razor bug or Razor gotcha =. @* ... *@ placement
Dec 20, 2011 05:53 PM|LINK
in c# and many other languages, one can stick a comment almost anywhere without worry ...
in ASP.NET MVC 4, i just got this:
Parser Error Message: Expected a "{" but found a "@".
BLock statements must be enclosed in in "{" and "}".
AFAIK, the error message may be specific to CSHTML pages.
i caused this error thus:
@using(Html.BeginFrom("actionName", "controllerName")) @* ... this is a Razor comment ... *@ {the fix is simple enough ...
@* ... this is a Razor comment ... *@ @using(Html.BeginFrom("actionName", "controllerName")) {imho, i'd call it a bug, unless, of course, it's lurking somewhere in a design "You can not do that!" document.
regardless what's it's called, imho, it's counter-intuitive.
g.
gerrylowry
All-Star
20525 Points
5713 Posts
Re: ASP.NET MVC 4: Razor bug or Razor gotcha =. @* ... *@ placement
Dec 20, 2011 05:57 PM|LINK
P.S.:
the bad news is, it gets caught at run time ...
which can be could news too because i got to test my custom error page (Error.cshtml).
g.
zpbappi
Member
112 Points
21 Posts
Re: ASP.NET MVC 4: Razor bug or Razor gotcha =. @* ... *@ placement
Dec 21, 2011 08:24 AM|LINK
I would say, the syntax parsing algorithm didn't think anyone would put comments there. LOL. MVC4 developers must find and fix this issue ASAP.
By the way, good catch. :)
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: ASP.NET MVC 4: Razor bug or Razor gotcha =. @* ... *@ placement
Dec 21, 2011 04:41 PM|LINK
I think this is how razor is working currently. Look at this examples,
@if(true)
@* ... this is a Razor comment ... *@
{
}
This will show a parse error but this will not,
@if(true){
@* ... this is a Razor comment ... *@
}
The fact is that Razor expect a curly brace immediatly after the code block because You cannot use single-statement control-flow statements in CSHTML pages.
Now look this. It will show you,
A space or line break was encountered after the "@" character. Only valid identifiers, keywords, comments, "(" and "{" are valid at the start of a code block and they must occur immediately following "@" with no space in between.
@
@* This is a comment. *@
{
}
But this will work,
@{
@* This is a comment. *@
}
Every parser have some rules and razor have this rule.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
gerrylowry
All-Star
20525 Points
5713 Posts
Re: ASP.NET MVC 4: Razor bug or Razor gotcha =. @* ... *@ placement
Dec 21, 2011 05:51 PM|LINK
@ imran_ku07
Hi imran ... while that's a good point, in this case, i disagree with you.
Let me explain.
Some languages are column specific, for example RPG; for column specific languages, one must, for example, code operands in fixed columns, operators in different fixed columns, et cetera.
OTOH, for most, if not all, other programming languages, the code space is either white space or not white space; in such cases, the fundamental rule of parsing is to ignore white space; FWIW, comments are usually deemed to be white space.
g.
gerrylowry
All-Star
20525 Points
5713 Posts
Re: ASP.NET MVC 4: Razor bug or Razor gotcha =. @* ... *@ placement
Dec 21, 2011 05:55 PM|LINK
@ imran_ku07
BTW, imho, what makes this parsing anomaly especially toxic is that a run time exception results from it.
g.
ignatandrei
All-Star
135210 Points
21690 Posts
Moderator
MVP
Re: ASP.NET MVC 4: Razor bug or Razor gotcha =. @* ... *@ placement
Dec 21, 2011 08:34 PM|LINK
Do you have
MVCBuildViews
to true?
gerrylowry
All-Star
20525 Points
5713 Posts
Re: ASP.NET MVC 4: Razor bug or Razor gotcha =. @* ... *@ placement
Dec 21, 2011 08:57 PM|LINK
@ ignatandrei
hi ignat, i do not understand why you are asking this particular question. please elaborate.
thnx/rgds/gerry
ignatandrei
All-Star
135210 Points
21690 Posts
Moderator
MVP
Re: ASP.NET MVC 4: Razor bug or Razor gotcha =. @* ... *@ placement
Dec 21, 2011 09:02 PM|LINK
If you edit your csproj/vbproj file and put MVCBuildViews to true, the gotcha will be raised at compile time.
XIII
All-Star
182708 Points
23464 Posts
ASPInsiders
Moderator
MVP
Re: ASP.NET MVC 4: Razor bug or Razor gotcha =. @* ... *@ placement
Dec 21, 2011 09:03 PM|LINK
Hi,
It's a way to have compile time checking of your views instead of execution time.
In the project file you should set the following to true:
I suggest you take a look at the following article: Compiling MVC Views In A Build Environment
Grz, Kris.
Interested in Azure, ASP.NET (MVC), jQuery, WCF, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!