parsing @ in MVC javascript section? [duplicate]

parsing @ in MVC javascript section? [duplicate]


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 @.



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会


@@ should do it.


The best solution would be using the HTML-encoded character string for the @-character: @ Dec 18 '13 at 12:45


posted @ 2021-10-29 10:32  ChuckLu  阅读(4)  评论(0编辑  收藏  举报