Inserting razor syntax inside javascript function

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Inserting razor syntax inside javascript function



Im trying to loop over a collection of data inside a div like this but received and error that says Unterminated string literal. Strings that start with a quotation mark (") must be terminated before the end of the line. How can i solve this?


<a href="@(eventItem.Url)" class="media-box__cover">
@if (listingImageUrl == "") {
if (currentCount % 2 == 0) {
<div class="media-box__cover-image" style="background-color: #ffd205;"></div>
}else {
<div class="media-box__cover-image" style="background-color: #0d9430;"></div>
}
} else {
<div class="media-box__cover-image" style="background-image: url('@(listingImageUrl)');"></div>
}
</a>



into this,


for (i = 0; i < json["data"].length ; i++) {
if(typeof(json["data"][i]) == 'object' && json["data"][i] != null){

htmlRetStr = "<div class='block'><div class='media-boxes'>";
htmlRetStr += "<div class='media-box'>";
htmlRetStr += "<a href=""+ json["data"][i]["eventUrl"] +"" class='media-box__cover'>";
htmlRetStr += "@if (json["data"][i]["eventUrl"] == '') { "; //error here
htmlRetStr += "if (currentCount % 2 == 0) {";
htmlRetStr += "<div class='media-box__cover-image' style='background-color: #ffd205;'></div>";
htmlRetStr += "}else{";
htmlRetStr += "<div class='media-box__cover-image' style='background-color: #0d9430;'></div> }";
htmlRetStr += " } else {";
htmlRetStr += "<div class='media-box__cover-image' style='background-image: url(""+ json["data"][i]["listingImage"] +"");'></div>} </a>";
htmlRetStr += "<div class='media-box__main'><div class='media-box__main-inner'><div class='media-box__header'>";
htmlRetStr += "<h3 class='media-box__heading'><a href=""+ json["data"][i]["eventUrl"] +"" class='media-box__heading-link'>" + json["data"][i]["heading"] + "</a></h3>";
htmlRetStr += "<div class='media-box__meta'>Posted on: " + json["data"][i]["articleDate"] +" "+ json["data"][i]["articleMonth"] +" "+ json["data"][i]["articleYear"] + "</div></div>";
htmlRetStr += "<p>"+ json["data"][i]["subHeading"] +"&hellip;</p>";
htmlRetStr += "</div></div></div></div></div>";

$("#news").append(htmlRetStr);
}









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived