在MVC javascript部分解析@? [英] parsing @ in MVC javascript section?
本文介绍了在MVC javascript部分解析@?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在MVC4的javascript部分使用电子邮件 RegEx
。但 RegEx
有@ char。它不允许解析它
I am trying using Email RegEx
in javascript section in MVC4. But RegEx
has @ char. It is not allowing to parse it
error:
Parser Error Message: "[" is not valid at the start of a code block.
Only identifiers, keywords, comments, "(" and "{" are valid.
代码
code
@section scripts{
<script type="text/javascript">
$(document).ready(function() {
$('#btnSave, #btnCoAuthor').click(function() {
if (form.valid()) {
var hasError = false;
var emailReg = '[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4}';
//Error showing @
推荐答案
您需要为Razor 转义 @
,而不是JS字符串本身。所以,只需使用 @@
。一旦Razor呈现HTML,它最终只会是 @
。
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 @
.
这篇关于在MVC javascript部分解析@?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文