Reputation: 2621
in a controller I am trying to render json to a specific view. Here is what I was doing before using json :
def create() {
render(view: "/book/create", model: [bookInstance: new Book(params)])
}
How would I render to a specific view like above but return json instead ? I have tried a few things like the following :
def create() {
def bookInstance = new Book(params)
render(view:"/book/create", model: [bookInstance as JSON] );
}
I have imported the required JSON library.
Thanks.
Upvotes: 0
Views: 1277
Reputation: 12238
The model is expecting a map. You can't just put anything in there without a key. Your first example has the setup:
render(view: "/book/create", model: [bookInstance: bookInstance as JSON])
Upvotes: 1