简体   繁体   中英

pass a value from gsp to controller

I have something like this

<g:each in="${category}" status="i" var="cat">
   <li class="demo_li"><g:link action="listGame"><img id= "icon" src="${resource(dir: 'icons', file: "${cat.icon}")}"><div>${cat.categoryName}</div></g:link></li>

I want to pass the value of ${cat.categoryName} to the controller if i click on it how do I do this?

The Grails g:link tag has a params attribute you can use to pass parameters to a controller action. The params is a Map . Lets say you name the parameter categoryName . You'd specify it like this:

<g:link action="listGame" params="${[categoryName: cat.categoryName]}">..</g:link>

In your controller's listGame() action you can access the parameter like this: params.categoryName

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM