Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Razor brackets inside code block

I'm having issues do linq queries inside of a code block.

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

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

like image 604
Matthew Avatar asked Sep 06 '12 13:09

Matthew


2 Answers

Remove the @ from Model:

@{
  var foo = Model.Things.Select((value, index) => new { value, index });
}
like image 140
eouw0o83hf Avatar answered Nov 07 '22 04:11

eouw0o83hf


Please try

@{
 var foo = Model.Things.Select((value, index) => new { value, index });
}
like image 27
petro.sidlovskyy Avatar answered Nov 07 '22 04:11

petro.sidlovskyy