I've created a JSON array from a database and I have it set up in a controller like so:
public ActionResult highlight()
{
var statesHighlight =
db.Jobs
.Select(r => r.State);
return Json(statesHighlight , JsonRequestBehavior.AllowGet);
}
How do I set this as a JavaScript variable in my view? I'm sure there's a simple way, but I can't seem to figure it out. Do I use @Html.Action or @Url.Action?
EDIT: Here's how I currently have my data hard coded for the plugin I'm 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-sparated 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>