Is this normal? Am I doing something wrong or is it a bug?
I've been using this solution for a year now but it annoys me to have to use it without knowing why...
If I declare variables, strings or whatever in a codeblock and follow with a switch or a if statement it throws a error on the front-end and in Visual studio about a missing bracket.
In this example if I don't use the span Visual studio intellisense stops working at else.
If you are in a code block, ie your for each the variable should be found without the @, effectively this breaks the code block.
The span, ends the @countryCode first block, so throws no error, but the second @countryCode breaks the previous, hence you have an extra curly bracket on the end.
Ok, tried to explain, but sounds really stupid.
Try it without the @ on countryCode, should clear it up
Strange razor syntax error
I'm always having a weird issue with razor in umbraco. I found a solution but it is ugly and I just want to know if I'm doing something wrong...
If I for instance want to use this code in a partial view:
I's missing a bracket }
If I add a empty span or even in the code between the strings and the If-else block it works without an error.
example:
Is this normal? Am I doing something wrong or is it a bug? I've been using this solution for a year now but it annoys me to have to use it without knowing why...
Frans
Comment author was deleted
Not sure I follow what you mean, so the first one gives an error? And adding the empty span get's rid of that error?
The last example gets rid of the error.
If I declare variables, strings or whatever in a codeblock and follow with a switch or a if statement it throws a error on the front-end and in Visual studio about a missing bracket.
In this example if I don't use the span Visual studio intellisense stops working at else.
Comment author was deleted
And it's all surrounded in a code block so @{} ? What is the error you get?
In this case its wrapped in a
@foreach(){ }
Hi
It's probably the @ on the variable countryCode.
If you are in a code block, ie your for each the variable should be found without the @, effectively this breaks the code block.
The span, ends the @countryCode first block, so throws no error, but the second @countryCode breaks the previous, hence you have an extra curly bracket on the end.
Ok, tried to explain, but sounds really stupid.
Try it without the @ on countryCode, should clear it up
Regards
Gary
Gary I think you've done a great job of explaining it!
I always think of "entering code mode" - either a @ or a @{ will start code mode.
When you're in a @{ section you'll "exit" code mode if you open an html tag.. but re-enter it when you close the tag.. confusing.. yeah just a bit!
So in short, don't use @ on variables in the middle of code blocks.
Nice catch Gary,
I saw I use the @ in every project. on every variable I declare.
I'll try it tomorrow when I'm at work.
And of course that was the solution.
So If I'm in a codeblock I can't use a @ unless I break the codeblock with HTML than I have to use a @.
Thanks a lot Gary. You've made my week :P
is working on a reply...