Sunday, May 12, 2024
85
rated 0 times [  89] [ 4]  / answers: 1 / hits: 21802  / 12 Years ago, thu, july 12, 2012, 12:00:00

I have seen some posts regarding this topic and a few blogs, but none seem to mention the output I'm getting.



What I want is to generate a google maps map with information on it. Manually entering the information results in the correct information. So that part works.



Where I'm getting stuck is when I'm going to dynamiccaly create the javascript array with the string with the information I want on my map.



The html code I want to get is:



<script type=text/javascript>     
var projects = [
['Kantoor 4.1 bestaande bouw', 52.25446, 6.16024700000003, 'Deventer', '', 'adviseurs', 'rating30'],
['School nieuw 4.0', 52.243161, 4.43677860000003, 'Noordwijk', '', 'adviseurs', 'rating30'],
];


Very simple javascript array, which I thought to create with:



<script type=text/javascript>
var projects = [
@foreach (var item in Model)
{
@HttpUtility.JavaScriptStringEncode([' + item.Gebouwnaam + ', + item.LocatieLatitude.ToString().Replace(,, .) + , + item.LocatieLongitude.ToString().Replace(,, .) + , ' + item.Plaats + ', ' + item.Gebruiksfunctie + ', ' + item.Licentiehouder + ', ' + item.rating + '],);
}
];
</script>


However this gives me:



<script type=text/javascript>
var projects = [
[u0027Kantoor 4.1 bestaande bouwu0027, 52.25446, 6.16024700000003, u0027Deventeru0027, u0027u0027, u0027adviseursu0027, u0027rating30u0027],
[u0027School nieuw 4.0u0027, 52.243161, 4.43677860000003, u0027Noordwijku0027, u0027u0027, u0027adviseursu0027, u0027rating30u0027],
];
</script>


Escaping the single quotes doesn't work.
What am I doing wrong?


More From » asp.net-mvc-3

 Answers
8

Just tried with



 <script type=text/javascript>
var projects = [

@Html.Raw([' + aaa + ', ' + bbb + '],)


];
</script>


it worked and showed ...



<script type=text/javascript>
var projects = [

['aaa', 'bbb'],


];
</script>

[#84311] Wednesday, July 11, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emiliano

Total Points: 381
Total Questions: 109
Total Answers: 93

Location: Jersey
Member since Fri, Oct 1, 2021
3 Years ago
emiliano questions
;