Asp.net mvc 使用JavaScript时,如何在Razor页面下转义@

Asp.net mvc 使用JavaScript时,如何在Razor页面下转义@,asp.net-mvc,angularjs,asp.net-mvc-4,Asp.net Mvc,Angularjs,Asp.net Mvc 4,我正在学习AngularJS,并提出了这个问题: <div ng-controller="MainCtrl as ctrl"> <form ng-submit="ctrl.submit()" name="myForm"> <input type="text" ng-model="ctrl.user.username" ng-pattern="/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[

我正在学习AngularJS,并提出了这个问题:

<div ng-controller="MainCtrl as ctrl">
<form ng-submit="ctrl.submit()" name="myForm">
    <input type="text"
           ng-model="ctrl.user.username"
           ng-pattern="/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/"
           ng-required="true"
           ng-minlength="4">
    <input type="password"
           ng-model="ctrl.user.password"
           ng-required="true">
    <input type="submit"
           value="Submit"
           ng-disabled="myForm.$invalid">
</form>

在语句
“ng pattern=“/^[A-Za-z0-9.\u%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/”
中,我想使用
'
但我不能。我尝试了
@
但它也不起作用。它给了我这个错误:

“[”在代码块的开头无效。只有标识符, 关键字、注释、“(”和“{”有效


演示:

使用双精度“
@
”或声明一个字符串变量来分配模式并使用。如下所示

@{
   string tempstr = "/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/";
}
<div ng-controller="MainCtrl as ctrl">
<form ng-submit="ctrl.submit()" name="myForm">
    <input type="text"
           ng-model="ctrl.user.username"
           ng-pattern="@tempstr"
           ng-required="true"
           ng-minlength="4">
    <input type="password"
           ng-model="ctrl.user.password"
           ng-required="true">
    <input type="submit"
           value="Submit"
           ng-disabled="myForm.$invalid">
</form>
@{
字符串tempstr=“/^[A-Za-z0-9.\%+-]+@[A-Za-z0-9.-]+\[A-Za-z]{2,4}$/”;
}

希望对您有所帮助,谢谢。

请使用双精度“
@
”或声明一个字符串变量来分配模式并使用。如下所示

@{
   string tempstr = "/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/";
}
<div ng-controller="MainCtrl as ctrl">
<form ng-submit="ctrl.submit()" name="myForm">
    <input type="text"
           ng-model="ctrl.user.username"
           ng-pattern="@tempstr"
           ng-required="true"
           ng-minlength="4">
    <input type="password"
           ng-model="ctrl.user.password"
           ng-required="true">
    <input type="submit"
           value="Submit"
           ng-disabled="myForm.$invalid">
</form>
@{
字符串tempstr=“/^[A-Za-z0-9.\%+-]+@[A-Za-z0-9.-]+\[A-Za-z]{2,4}$/”;
}
希望能有所帮助,谢谢。

另一种方法是:

ng-pattern="/^[A-Za-z0-9._%+-]+@("@")[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/"
另一种方法是:

ng-pattern="/^[A-Za-z0-9._%+-]+@("@")[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/"

您是否真的在使用第页上的任何viewModel?如果否,则将其转换为html页…可能的副本您是否真的在使用第页上的任何viewModel?如果否,则将其转换为html页…可能的副本