未捕获的SyntaxError:意外的标记ILLEGAL ASP.NET mvc3

Nic*_*Nic 0 javascript c# jquery asp.net-mvc-3

假设我有以下字符串:

var myString =" <ol>\r\n<li>Some text</li>\r\n</ol>";

当我试图提醒(myString)时一切正常,但是,

假设我有模型:

public class MyModel
{
   public string TestProperty{get;set;}
}
Run Code Online (Sandbox Code Playgroud)

在控制器中我TestProperty=myString 在视图中设置 :

@model MyModel
<script>
    jQuery(document).ready(function() {
        alert('@Model.TestProperty')// here I am getting error Uncaught SyntaxError: Unexpected token ILLEGAL
    })
</script>
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚问题是什么,以及如何解决它.非常感谢您的关注.

Jas*_*n P 5

您生成的javascript如下所示:

http://jsfiddle.net/MhtEL/

alert('<ol>
      <li>sometext</li>
      </ol>');
Run Code Online (Sandbox Code Playgroud)

哪个是无效的javascript(字符串文字不能跨越多行).

您可以先替换换行符:

alert('@Model.TestProperty.Replace("\r\n", "")')
Run Code Online (Sandbox Code Playgroud)