0

I am trying to get my controller to return a named JSON array. It currently returns JSON formatted like this:

[{"Title":"Star Wars: A New Hope","Year":1977},{"Title":"Star Wars: The Empire Strikes Back","Year":1980},{"Title":"Star Wars: Return of the Jedi","Year":1983}]

But I want it like this

movies:[{"Title":"Star Wars: A New Hope","Year":1977},{"Title":"Star Wars: The Empire Strikes Back","Year":1980},{"Title":"Star Wars: Return of the Jedi","Year":1983}]

Here is my controller method:

public JsonResult GetMovies()
{
    var model = _movies;


    return Json(model, JsonRequestBehavior.AllowGet);
}

Any ideas?

1 Answer 1

3

You can return anonymous json object like

 return Json(new {
        movies = model
    } , 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.