Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello I have this code in my `ASP.NET Razor v2 cshtml` file that should load `string` into this paragraph the variable is from `c# list of strings` but when the `string` that is loaded contains something like this:
C#
+ "<p>"+'Rejv&#237;zsk&#225; 113 79001 Jesen&#237;k'+"</p>"

I get this JavaScript critical error: `SCRIPT1015: Unterminated string constant`

The program fails because some character escaped my `ending quotation mar` `'`

Actually the code looks like this:
C#
"<p>"+'@string.Format(serviceDescription[i])'+"</p>"

serviceDescription is list of strings that may containt whatever value that can escape my `'` character.

May I please know how to correct this?

This code is used in adjusting `InfoWindow in Google API`

So far I tried and non of these method worked:
C#
+ "<p>"+' @string.Format("<p>{0}</p>", serviceDescription[i])'+"</p>"

+ "<p>"+'@string.Format(serviceDescription[i])'+"</p>"

+ "<p>"+'@string.Format("{0}", @Html.Raw(serviceDescription[i]))'+"</p>"

+ "<p>"+' @(new HtmlString(serviceDescription[i]))'+"</p>"

+ "<p>"+' @Html.Raw(serviceDescription[i])'+"</p>"

+ ' @Html.Raw("<p>"+@serviceDescription[i]+"</p>")'

+ @(new HtmlString("<p>"+serviceDescription[i]+"</p>"))
Posted

1 solution

you can use the html encoding in this link http://www.naveen.com.au/javascript/jquery/encode-or-decode-html-entities-with-jquery/289[^].

Or you can use multiple replace() as described in this link http://jsperf.com/htmlencoderegex/25[^] as well as (Remove Line Breaks with Javascript) in this link http://www.textfixer.com/tutorials/javascript-line-breaks.php[^]. Hope this help you
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900