4

Possible Duplicate:
Escape @ character in razor view engine

how can i use '@' symbol in my script code in the MVC page (razor engine)

write a code like this :

<script>
var a = "this is a test text with @ symbol";

alert(a);
</script>
Community
  • 1
  • 1
MHF
  • 511
  • 8
  • 22

4 Answers4

5

You can escape by use of two ampersat symbols: @@.

var a = "this is a test text with @@ symbol";

As an aside, though I recently learned and think those coming across this question might also find it useful: you can do comments with a combination of ampersat signs and asterisks:

@*this would comment out some code, or just allow for comments in general*@
Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
4

@@ should work to escape the character

jrummell
  • 42,637
  • 17
  • 112
  • 171
Willem D'Haeseleer
  • 19,661
  • 9
  • 66
  • 99
2
var a = "this is a test text with "+<text>@</text>+" symbol";
Yorgo
  • 2,668
  • 1
  • 16
  • 24
2

To escape an @ symbol you need to double it up like so:

@@
Robbie
  • 18,750
  • 4
  • 41
  • 45