Reputation: 114
I'm trying to send a string of JSON to the client from a database for a JavaScript plugin to highlight the states it gets back. However, in addition to the state information I need, I'm also getting the variable name. Is there anyway I can correct the formatting so that instead of it looking like this:
{"statesHighilght":["California","Washington","Utah","Utah","Florida","Kansas","Utah"]}
I get this:
["California","Washington","Utah","Utah","Florida","Kansas","Utah"]
This is what my controller code looks like:
public ActionResult highlight()
{
var statesHighlight =
db.Jobs
.Select(r => r.State);
return Json(new { statesHighilght }, JsonRequestBehavior.AllowGet);
}
Upvotes: 0
Views: 505
Reputation: 4471
Pass the enumerable directly to the Json
method instead of wrapping it in an anonymous object.
return Json(statesHighlight, JsonRequestBehavior.AllowGet);
Upvotes: 4