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

  • Home
  • SEARCH
  • 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 8310825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:36:01+00:00 2026-06-08T19:36:01+00:00

Using ASP.NET MVC 3 with C# I have a web page to display a

  • 0

Using ASP.NET MVC 3 with C# I have a web page to display a map onto which I want to add a polyline consisting of several latitude and longitude coordinates. With the Leaflet JavaScript library you can add GeoJson layers. I want to get the longitude and latitude coordinates from a Database in C# and pass the list of coordinates to the JavaScript to create GeoJson or as GeoJson.

Here is an example of the GeoJson I wish to create:

var polyline = {
      "type": "Feature",
      "geometry": {
      "type": "LineString",
                    "coordinates": [
                        [-105.00341892242432, 39.75383843460583],
                        [-105.0008225440979, 39.751891803969535] …
                    ]
                },
      "properties": {
      "popupContent": "This is a polyline of many coordinates.",
      "underConstruction": false
      }
};

How can I create GeoJson similar to that shown above and add location data to the “coordinates” section from the C# or JavaScript and then use it in JavaScript to add a layer as such:

var myLayer = L.geoJson().addTo(map);
myLayer.addData(polyline);

I have started using GeoJSON.net and have come up with this code:

foreach (Position point in Positions)
{
    coordinates.Add(point);
}

GeoJSON.Net.Geometry.LineString line = new GeoJSON.Net.Geometry.LineString(coordinates);

JavaScriptSerializer serializer = new JavaScriptSerializer();

var data = serializer.Serialize(lineString);

But I do not know how to pass this GeoJSON LinseString object from the C# to the JavaScript. i was unable to pass it using Json as such:

return Json(data, JsonRequestBehavior.AllowGet);
  • 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-08T19:36:05+00:00Added an answer on June 8, 2026 at 7:36 pm

    Just looked briefly at GeoJSON.NET and it uses JSON.NET, so you need to use the JSON.NET serializer when you return your result (the JSON serializer in .NET does not know about the JSON.NET attributes.) To do this you could just serialize and return a ContentResult like this (haven’t tested this):

    var line = new GeoJSON.Net.Geometry.LineString(coordinates);
    string json = JsonConvert.SerializeObject(line);
    return Content(json, "application/json");
    

    or better you could use a custom JSON.NET ActionResult.

    On a side note, there seems to be an issue with serialization of polygons not complying with the GeoJSON specification – not sure if this also affects polylines. But the fact that this has not been fixed a year on, does not promise good for a GeoJSON library. The project seems to be abandoned.

    We opted for using the GeoJSON serialization in nettopologysuite, which worked straight out of the box as I remember.

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

Sidebar

Related Questions

I'm working on a Web project using Asp.Net MVC, which I'll have to deploy
I'm using ASP.net MVC C# in Visual Studio Web Dev. I have a couple
I have downloaded the ASP.NET MVC 2 Release version (using Web Platform Installer) as
I am developing an ASP.Net MVC 3 Web application using Razor Views. I have
I'm using ASP.NET MVC and have a model which has an image (byte array)
I'm using ASP.NET MVC 2 and have a login page that is secured via
I am using ASP.NET MVC 1.0. I have an ActionResult which receives a form
We will be using custom Silverlight 4.0 controls on our ASP.NET MVC web page
using ASP.NET MVC 2 I have a navigation menu inside my Master Page. In
I have developed a website using Asp.Net MVC which uses a SQL CE database

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.