0

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);
}

1 Answer 1

4

Pass the enumerable directly to the Json method instead of wrapping it in an anonymous object.

return Json(statesHighlight, JsonRequestBehavior.AllowGet);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.