如何直接向另一个动作提交按钮

Tom*_*máš 5 grails

如何跳转到控制器中的另一个动作?

我有表单和几个提交按钮.每个submmit按钮都有名称.

<g:form action="save" method="post">
   <g:input name="title" value="${letter.title}" />
   <g:input name="comments[0].text" value="${letter.comments[0].text}" />
   <g:submitButton name="save" value="save" />
   <g:submitButton name="addComment" value="add" />   
</g:form>

def save = {

     if (params.addComment){
       letter.addToComents(  new Comment() ) 
       render(view:'form', model:["letter": letter])
       return
     }

    ...
    if ( letter.save() ) 
    ...
}

def addComment = {
      ...
    }
Run Code Online (Sandbox Code Playgroud)

它有效,但并不好.我想将块"addComment"中的代码移动到动作addComment:

def save = {

     if (params.addComment){
       // it don´t work
       redirect ( action:"addComment" )
     }

    ...
    if ( letter.save() ) 
    ...
}

def addComment = {
      letter.addToComents(  new Comment() ) 
      render(view:'form', model:["letter": letter])
      return
    }
Run Code Online (Sandbox Code Playgroud)

还是存在更好的解决方案?这会很好:

<g:submitButton name="save" value="save" action="save" />
<g:submitButton name="addComment" value="add" action="addComment"  /> 
Run Code Online (Sandbox Code Playgroud)

非常感谢汤姆

Mik*_*ler 13

请改用g:actionSubmit标记.

        <g:form  method="post">
           <g:input name="title" value="${letter.title}" />
           <g:input name="comments[0].text" value="${letter.comments[0].text}" />
           <g:actionSubmit action="save" value="Save" />
           <g:actionSubmit action="addComment" value="Add Comment" />   
        </g:form>   
Run Code Online (Sandbox Code Playgroud)