ASP.NET Razor与JavaScript';小于';符号(<;)可以';无法解析

ASP.NET Razor与JavaScript';小于';符号(<;)可以';无法解析,javascript,asp.net,razor,Javascript,Asp.net,Razor,我正在尝试将一些javascript与服务器端变量结合起来 在这里,我试图替换“试试这个: 注意,它必须在脚本标记之间才能工作..(我假设是这样的) @{ 字符串年龄='1';//假设我是从查询字符串中得到的 @:$('select1').val('age'.replace('code>@{ 字符串年龄='1';//假设我是从查询字符串中得到的 var LESS_THAN_CHARCODE=60;//相当于特殊字符“,我最终使用@(Html.Raw)(“我会将“age”保存在js变量中,并在r

我正在尝试将一些javascript与服务器端变量结合起来

在这里,我试图替换“试试这个:

注意,它必须在脚本标记之间才能工作..(我假设是这样的)


@{
字符串年龄='1';//假设我是从查询字符串中得到的
@:$('select1').val('age'.replace('code>@{
字符串年龄='1';//假设我是从查询字符串中得到的

var LESS_THAN_CHARCODE=60;//相当于特殊字符“,我最终使用@(Html.Raw)(“我会将“age”保存在js变量中,并在razor代码块之外进行替换。记住,这只适用于:)哦,不。我已经在这里添加了注释。很抱歉造成混淆。
@{
  string age = '&lt;1'; // assume I got it from the QueryString 
  <text>$('#select1').val('@age'.replace('&lt;','<'));</text> // and when the parser sees the '<' symbol it thinks I'm trying to close the <text> tage
}
<script>
@{
  string age = '&lt;1'; // assume I got it from the QueryString 
  @: $('#select1').val('@age'.replace('&lt;','<')); // and when the parser sees the '<' symbol it thinks I'm trying to close the <text> tage
}
</script>
<text>
    @{
      string age = '&lt;1'; // assume I got it from the QueryString 
      <text>var LESS_THAN_CHARCODE = 60;</text> // equivalent for the special character '<' (less than symbol)
      <text>$('#select1').val("@age".replace('&lt;',String.fromCharCode(LESS_THAN_CHARCODE)))</text>
    }