What does your Model look like? Additionally, it's a bit hard to tell if you want to actually access these model values within C# or within Javascript because Javascript isn't going to really be aware of what the model itself looks like unless you explicitly
write some code to store it there (which I assume your `addMarker()` function calls do).
Without knowing a bit more, it's difficult to tell, although it seems like since you have access to your latitude and longitude within your existing foreach call, you'd be able to handle this there.
The Model in your page view is a single type, while the forEach() method calls a function once for each element in an
array. So, maybe you can show us your model.
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.
you are referencing Model as a javascript variable, but it is never defined. Also you are mine C# and javascript. you shod just serialize the Model to javascript variable, and do the code in javascript instead of mixing:
var model = @(JsonConvert.SerializeObject(Model)); // serialize MVC model to json string and assign to javascript variable
Member
40 Points
158 Posts
Access Model.LocationList in the Model.ForEach Loop
Mar 05, 2020 04:32 AM|shijostephen|LINK
Hi
How to access Model.LocationList in the Model.ForEach Loop
Model.forEach is not working here
Thanks & Regards
Shijo
All-Star
114593 Points
18503 Posts
MVP
Re: Access Model.LocationList in the Model.ForEach Loop
Mar 05, 2020 05:47 AM|Rion Williams|LINK
What does your Model look like? Additionally, it's a bit hard to tell if you want to actually access these model values within C# or within Javascript because Javascript isn't going to really be aware of what the model itself looks like unless you explicitly write some code to store it there (which I assume your `addMarker()` function calls do).
Without knowing a bit more, it's difficult to tell, although it seems like since you have access to your latitude and longitude within your existing foreach call, you'd be able to handle this there.
Member
40 Points
158 Posts
Re: Access Model.LocationList in the Model.ForEach Loop
Mar 05, 2020 05:56 AM|shijostephen|LINK
Hi,
This is the entire code of the index.chtml page
I am trying to connect all the locations by line in the map, the locations are passed from the controller.
Thanks & Regards
Shijo
Participant
1320 Points
491 Posts
Re: Access Model.LocationList in the Model.ForEach Loop
Mar 05, 2020 07:44 AM|jiadongm|LINK
Hi shijostephen,
@model Tasks.Models.LocationLists
The Model in your page view is a single type, while the forEach() method calls a function once for each element in an array. So, maybe you can show us your model.
Best Regards,
Jiadong Meng
All-Star
58234 Points
15673 Posts
Re: Access Model.LocationList in the Model.ForEach Loop
Mar 05, 2020 04:09 PM|bruce (sqlwork.com)|LINK
in the code:
you are referencing Model as a javascript variable, but it is never defined. Also you are mine C# and javascript. you shod just serialize the Model to javascript variable, and do the code in javascript instead of mixing:
var model = @(JsonConvert.SerializeObject(Model)); // serialize MVC model to json string and assign to javascript variable