Afif Lamloumi Afif Lamloumi - 1 month ago 4x
ASP.NET (C#) Question

javascript float error

i did this code
File Real.cs

public ActionResult Index() {
IList<Eventdata> liste = DATA2.Eventdata.GetEventdata();
int a = liste.Count;

float lat = liste[a-2].Latitude;
float longi = liste[a-2].Longitude;
IList<float> model = new List<float>();
return View(model);

i mapped the table EventData : it contains two attributs floats ( Latitude,Longitude) and i want to know its last values.

File Index.CShtml

@model IList<float> @{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Lay3.cshtml";

<body onload="initialize(@Model[0],@Model[1])">
<div id="map_canvas" style="width: 800px; height: 500px;">
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript">
<script type="text/javascript" src="">
<script type="text/javascript">

function initialize(a, b) {
var myLatLng = new google.maps.LatLng(a,b);

var myOptions = {
zoom: 30,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.TERRAIN

var map = new google.maps.Map(document.getElementById("map_canvas"),
var flightPlanCoordinates = [
new google.maps.LatLng(a,b)

var flightmarker = new google.maps.Marker({
position: new google.maps.LatLng(a,b),
map: map, title: " denden"


and i have the last point like that :
and the
. but the messages are :
Why? And how can i correct it.


Try using( or set culture with '.' decimal digit separator)

<body  onload="initialize('@Model[0]','@Model[1]')"> // This will pass your value as
//two parameters(instead of four) but it can be used only as a string because
//javascript can parse decimal values only with '.' separator

Instead of

<body  onload="initialize(@Model[0],@Model[1])">

If you call initialize method with 34,75064 and 10,761744 you are actually passing four parameters. Because of that a = 34 and b = 75064.

You need to check culture when passing parameters from server to client because when culture have ',' insead of '.' for decimal digit separator your code wont work as expected.

In your case with map you need decimal value, so you can't use

<body  onload="initialize('@Model[0]','@Model[1]')">

You need to covert your decimal to appropriate culture like this

var culture = CultureInfo.GetCultureInfo("en-US");
<body  onload="initialize(@Model[0].ToString(culture), @Model[1].ToString(culture))">