user1577161
user1577161

Reputation: 175

Grails returning value from controller to gsp

I have been searching on how to return an integer value from controller to the gsp. I tried using this:

    def test(){
        def val = 1;
        return val;
    }

but it does not work. Please help.

Upvotes: 2

Views: 4014

Answers (3)

biniam
biniam

Reputation: 8199

The return statement is used to return values from services to controllers. If you want to pass values from the controller to gsp, use:

[variableNameInGSP : valueToBeReturned]

Upvotes: 2

ludo_rj
ludo_rj

Reputation: 3934

Add this code to your controller:

def test(){
    def v = 10
    render view:'test.gsp', model:[v:v]
   }

Then, access the value from your test.gsp by "${v}" Note that the render view is optional for test.gsp, i've written it only for demo purpose.. (i.e change the gsp filename).

Hope it helps.

Upvotes: 2

Manish
Manish

Reputation: 3968

Try

 def test(){
    def val = 1;
    [val:val]
   }

Upvotes: 4

Related Questions