0

I have some data in My controller which i want to use in Javascript in my gsp file

class MainController {
    def test = {

        def value = 111.10
    }
}

TEST.GSP

<html>
    <head><title>Simple GSP page</title></head>
    <body>
        <script language="JavaScript">
            alert("${value}")
        </script>
    </body>
</html>

Dialog box appears but without any value .. Any Solution ..?

Thanks

1 Answer 1

1

You need to explain grails, that he local variable value should be accessible in the view, by returning a map of all variables, that should be accessible in the view:

class MainController {
    def test = {

        def value = 111.10
        [value: value]
    } 
}
Sign up to request clarification or add additional context in comments.

1 Comment

it should be working, maybe you are in the wrong controller method. is your gsp name seriously upper case? double check, whether action name and view name is the same.

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.