I have retrieved a JSON array from a database and it is set up in a controller like this:
public ActionResult highlight()
{
var statesHighlight =
db.Jobs
.Select(r => r.State);
return Json(statesHighlight , JsonRequestBehavior.AllowGet);
}
How can I assign this as a JavaScript variable in my view? I believe there must be an easy way to do it, but I am unable to figure it out. Should I use @Html.Action or @Url.Action?
EDIT: This is how I currently have my data hardcoded for the plugin that I am using:
<script type="application/json" id="map-data">
["CA","UT","FL","MT","WA","KS","KS","UT"]
</script>
<script>
var data = $.parseJSON($('#map-data').text());
var cities = $.parseJSON($('#city-data').text());
$('img').mapster({
mapKey: 'state',
clickNavigate: true,
isSelectable: false,
highlight: false,
onConfigured: function () {
// make the array into a comma-separated list
var csv = data.join(',');
var city_list = cities.join(',');
// the 'set' activates the areas
$('img').mapster('set', true, csv, options = { fillColor: '638EA5' });
//altImage: '../Images/map_outline_blackStrokeDot.png'
$('img').mapster('set', true, city_list, options = { fillColor: 'ffffff' });
}
});
</script>