简体   繁体   中英

JS 'Unterminated string constant' error

On my view I have this:

@if(ViewBag.Test == true)
{
    <script>
        window.alert("test")
    </script>
}

Here is a picture:

在此处输入图片说明

As you can see, the red wave-line is saying that it is an Unterminated string constant .

How do I fix this?

It may be choking on the closing script tag.

Are you able to do something like the following:

string script = "<scr" + "ipt>window.alert('test');</scr" + "ipt>";
Response.Write(script);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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