Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8179889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:05:53+00:00 2026-06-07T00:05:53+00:00

I am returning a model from my controller that displays a grid. Works fine.

  • 0

I am returning a model from my controller that displays a grid. Works fine. I also need to use that same data to produce points on a google map. I have the following code set up in my prototype that I needed to replace:

            var locationsAll = [
                ["Pretty", 40.1508, -83.21],
                ["Little", 40.1308, -83.11],
                ["Smug", 40.001, -83.01],
                ["Troublemaker", 40.109, -83.291],
                ["Smallest", 40.08, -83.20]
                ];

            PlotpointsonMap(locationsAll);

So far so good. That works so I am converting this to javascript like so:

                @{
                    var locations = "[";
                   foreach (var gmap in Model.MapPoints )
                   {
                       locations += "['" + gmap.EventStringData + "'," + gmap.Latitude + "," + gmap.Longitude + "],";
                   }

                    locations = locations.TrimEnd(',') + "]";

                }

            var myLocations = @locations;
            PlotpointsonMap(myLocations);

However, this half works. I am getting the following code in my javascript block when I view the source generated:

var myLocations = [["update",40.080398,-83.139141] 

I need it to render like so:

var myLocations = [["update",40.080398,-83.139141]

Any ideas on how to accomplish this are greatly appreciated. I tried:

var myLocations = @Server.HtmlDecode(locations);

and it gave me the same result 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:05:54+00:00Added an answer on June 7, 2026 at 12:05 am

    Wooow, no! No manual JSON manipulation please. No commas, no quotes, no trims, no brackets please. That hearts.

    Simply use a JSON parser:

    <script type="text/javascript">
        var locationsAll = @Html.Raw(Json.Encode(
            Model.MapPoints.Select(x => new object[] 
            { 
                x.EventStringData, x.Latitude, x.Longitude 
            })
        ));
        PlotpointsonMap(locationsAll);
    </script>
    

    The JSON parser guarantees you now that no matter what data you have in this MapPoints it will always be properly encoded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a repository that is returning data from my database using Entity
I have problem with returning a partial view from a controller with different model
I'm having trouble returning data from my controller using an ajax post function. What
I'm returning some Json via a C# MVC Controller. Other browsers work fine, but
I have a problem while returning jsp from controller using ajax+spring mvc. I want
The controller should ideally be free from domain logic right? How does that match
I'm trying to build VERY basic model->controller->view structure with CodeIgniter. I'd rather use models
I have a form that gets populated with data from the database. Before is
In my model I have three complex scopes returning the Discount object arrays. Each
In my rails app the model is fetching some XML and returning an array.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.