parsing @ in MVC javascript section? [duplicate]
回答1
You need to escape the @ for Razor, not for the JS string, itself. So, just use @@. Once Razor renders the HTML, it will end up as just an @.
回答2
Escaping with @@ works for me
var emailReg = '[-0-9a-zA-Z.+_]+@@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4}';
and output HTML is
var emailReg = '[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4}';
Escape @ character in razor view engine会
回答1
@@ should do it.
评论
The best solution would be using the HTML-encoded character string for the @-character: @
– WΩLLE - ˈvɔlə
Dec 18 '13 at 12:45