You are correct, but your first code example is missing a } in the end.
@{ <!-- Here you open a bracket
var noticeType = "";
var nt = @Umbraco.Field("noticeType").ToString();
switch(nt){ <!-- Here you open another bracket
case "1" : noticeType = "AAA";
break;
case "2" : noticeType = "BBB";
break;
case "3" : noticeType = "CCC";
break;
} <!-- Here you close a bracket (the switch)
<!-- Here you should close a bracket
Makes sense?
Other than that you are correct about text surrounded with @{ }.
Syntax of @
I had a problem posted earlier about { } but which I think is now something to do with my misunderstanding how the @ directive works in razor. Example
causes error
Compiler Error Message: CS1513: } expected
Source Error:
Line 79: } Line 80: } Line 81: }
However, if I separate the Razor into two blocks with the switch statement not in a @ block
it's fine.
Can someone explain why
is fine but
isn't? I thought surrounding text with @{ } meant 'anything within this is to be treated as Razor'?
Very confusing!!
Hi Tim.
You are correct, but your first code example is missing a } in the end.
Makes sense?
Other than that you are correct about text surrounded with @{ }.
Dennis
Thank you for the quick repsonse. However, I wasn't missing a } in my code - I just missed it when I copied it to this entry - my apologies.
I have corrected the original post.
I have tried again (just in case I was missing the closing } but I still get the crash. It must be something else.
Hi Tim,
I would try taking the @ away from the @Umbraco line.
I've used switches within Razor code blocks before and not had an issue so it does seem a bit strange.
Nik
As Nik said:
Removing the @ before Umbraco.Field("noticeType").ToString() solves it. Sorry i missed that..
Thank you Nik!
That's it - presumably the @Umbraco... thinks it is starting a new block.
Lesson learned!
That sounds logical.
Have a great day Tim! Good luck with the rest of the site!!
is working on a reply...