var itemlat=new Array();
var itemlong=new Array();
//add markers to map
@if (Model.LocationList != null)
{
foreach (var item in Model.LocationList)
{
@:addMarker(@item.Latitude, @item.Longitude, '@item.Title', '@item.Description', @item.LocationId);
}
}
var lineVertices = new Array();
var i = 0;
for (i = 0; i < 3; i++) {
var loc= new Microsoft.Maps.Location(@ViewBag.Collection1[i], @ViewBag.Collection2[i]);
var pin = new Microsoft.Maps.Pushpin(loc);
lineVertices.push(loc);
}
You should first convet the ViewBage value to json, then you can loop over the Array. Change it like below
var lineVertices = new Array();
var arr1 = @Html.Raw(Json.Encode(ViewBag.Collection1));
var arr2 = @Html.Raw(Json.Encode(ViewBag.Collection2));
var i;
for (i = 0; i < 3; i++) {
var loc= new Microsoft.Maps.Location(arr1[i], arr2[i]);
var pin = new Microsoft.Maps.Pushpin(loc);
lineVertices.push(loc);
}
Best Regards,
Jiadong Meng
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
Member
40 Points
158 Posts
The name 'i' does not exist in the current context
Mar 05, 2020 06:55 AM|shijostephen|LINK
Hi
I am getting below error in view
The name 'i' does not exist in the current context
controller
view
Thanks & Regards
Shijo
Participant
1320 Points
491 Posts
Re: The name 'i' does not exist in the current context
Mar 05, 2020 08:47 AM|jiadongm|LINK
Hi shijostephen,
You should first convet the ViewBage value to json, then you can loop over the Array. Change it like below
Best Regards,
Jiadong Meng