How to pass values from controller to view in grails 3

1.3k views Asked by At

In the controller I have which is having two values say name and amount.

In the controller I wrote

def d=[name:amount]
render (view: "/user.gsp", model: [user: d])

and in the view

${user}

This is giving the output as {name=amount}. But I want something like "My name and my amount".

How do I achieve that?

1

There are 1 answers

0
AudioBubble On

try this...

in controller

def create={           
        def customer = Customer.findAllByCif(cif)
        def getDOnumber= '(AUTO)'
//do anything and pass to view like this.


        [paramsCustomerCallat: customer, paramsparamsCustomerCallatView: getDOnumber]
    }

then you receive the params like this.

 <g:textField name="invoiceNo" value="${getDOnumber}" class="form-control" />

if you want to call that key and value in a record, i suggest you to change your code like this..

def d=[keyname:"name", keyamount:"myamount"]
render (view: "/user.gsp", model: [user: d])

then you can call like this in view

${user.keyname+" - "+user.keyamount}