Hi, I am facing an issue with the code in my ASP.NET Razor v2 cshtml file. I am trying to load a string into a paragraph from a C# list of strings. However, when the string being loaded contains certain characters, such as:
+ "<p>"+'Rejvízská 113 79001 Jeseník'+"</p>"
I encounter a JavaScript critical error:
SCRIPT1015: Unterminated string constant
This error occurs when some characters escape the closing quotation mark '
The code snippet in question looks like this:
"<p>"+'@string.Format(serviceDescription[i])'+"</p>"
The variable serviceDescription
is a list of strings that can contain values which may escape the '
character.
I'm seeking assistance in resolving this issue.
It's worth noting that this code snippet is utilized for adjusting the InfoWindow in the Google API.
I have already attempted several methods, none of which have worked:
+ "<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>")'
"<p>" @Html.Raw(String.Format(serviceDescription[i]))+"</p>"
+ @(new HtmlString("<p>"+serviceDescription[i]+"</p>"))
Here is the full code snippet for the InfoWindow:
var info = new google.maps.InfoWindow({
map: map
});
/* <img src="data:image/jpeg;base64{binary data}" /> */
google.maps.event.addListener(marker, 'click', function () {
var $infoWindowContent = $("<div style='line-height:1.35;overflow:hidden;white-space:nowrap;width: 200px'><h3>" + '@serviceTitle[i].ToString()'
+ '</h3><img <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="601312035d20131412090e074e260f120d0114">[email protected]</a>("data:{0};base64,{1}", serviceImgMIME[i], Convert.ToBase64String(serviceImgBinary[i])) style="width: 100%;max-height: 100%"/>'
+ "<p>"+ @Html.Raw(String.Format("{0}",serviceDescription[i]))+"</p>" // this is the line that causes me pain
+ "Web: " + "<a href="+'http://@string.Format("{0}", serviceLink[i])'+">"+'@serviceLink[i].ToString()'+"</a>"
+ "<br>"
+ "Kontakt: "+ "<a href="+'mailto:@serviceContact[i].ToString()'+">"+'@serviceContact[i].ToString()'+"</a>"
+ "<p>"+"Lze platit v: "+"<b>"+'@serviceIDCryptoCur[i].ToString()'+"</b>"+"</p>"
+ @switch (serviceIDCryptoCur[i])
{
case "BTC":
<text>
'<img height="20" width"20" src="~/Content/ikonky/btcSmall.png">'
</text>
break;
case "LTC":
<text>
'<img height="20" width"20" src="~/Content/ikonky/ltcSmall.png">'
</text>
break;
case "BTC,LTC":
<text>
'<img height="20" width"20" src="~/Content/ikonky/ltcSmall.png"> <img height="20" width"20" src="~/Content/ikonky/btcSmall.png">'
</text>
break;
default:
<text>
'<img height="20" width"20" src="~/Content/ikonky/btcSmall.png">'
</text>
break;
}
+ "</div>");
info.setContent($infoWindowContent[0]);
info.open(map, this);
});