简体   繁体   English

ASP.NET Razor页面中的未终止字符串常量错误

[英]Unterminated string constant error in ASP.NET Razor page

So I'm writing an ASP.NET MVC Web application and at the top of one of my razor pages i have this code: 因此,我正在编写一个ASP.NET MVC Web应用程序,在我的剃须刀页面之一的顶部,我有以下代码:

    <script type="text/javascript">
        alert("@TempData["alertMessage"]");
    </script>

If I understand the error 如果我理解错误

Unterminated string constant 未终止的字符串常量

correctly, it means I haven't closed the quotation marks. 正确,这表示我还没有关闭引号。 But if I look at the code it should be closed correctly right? 但是,如果我看一下代码,应该正确关闭它,对吗?

What is wrong about it? 怎么了

You should use single quotes in order to avoid the error . 您应该使用single引号以避免error

alert('@TempData["alertMessage"]');

With the other words you should wrap the statement within single quotes . 换句话说,您应该将语句用单quotes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM