i'm new in C# asp.net mvc. I'm making a ViewBag that contains Dictionary data type in controller and i want to get and display the value by javascript in .cshtml to code it with googlemaps function.
here's my dictionary & viewbag code from the controller:
Dictionary<string, string> alamatVehicleMarker = new Dictionary<string, string>();
alamatVehicleMarker.Add("v1","Bali");
alamatVehicleMarker.Add("v2","Jakarta");
alamatVehicleMarker.Add("v3","Bandung");
ViewBag.getAlamatVehicle = alamatVehicleMarker;
can you help me how to get the ViewBag.getAlamatVehicle in and how to loop through it please
EDITED
i've tried this :
<script>
function GetViewBagDictionary(id) {
@foreach (var item in ViewBag.getAlamatVehicle)
{
var key = item.Key;
var Value = item.Value;
if (key == id)
{
return Value;
}
}
return "not found";
}
<script>
but inside the if function it's give a error said that : The name 'id' does not exist in the current context