MVC Razor Brackets Inside Code Block

I am having problems with linq queries inside a code block.

@{ var foo = @Model.Things.Select((value, index) => new { value, index }); } 

The problem is the new {}, it sees the second bracket, closing the entire code block. Any way to avoid this?

+7
source share
2 answers

Remove @ from Model :

 @{ var foo = Model.Things.Select((value, index) => new { value, index }); } 
+13
source

Try

 @{ var foo = Model.Things.Select((value, index) => new { value, index }); } 
+5
source

All Articles