我有一个表单捕获一些数据,之后我想执行动作“generatehtmlreport”,如果用户点击生成html报告按钮并显示另一个按钮,点击此按钮,控制器动作“generatepdfreport”应该执行而主要的是html报告数据不应该去。这是我有的表格
<g:form name = "report_generation" id ="report_generation">
<input type = "hidden" name = "report_type" class = "report_type" value = "${reportType}"/>
<fieldset>
<legend class="form_legend">${reportTitle}</legend>
<div class="dialog">
<g:render template="/templates/filterTemplate" />
<div class="cb"></div>
</div>
</fieldset>
<div id = "report_buttons">
<input type = "submit" value = "Generate Report" class="td_link" name ="generate_report_html_btn" id = "generate_report_html_btn"/>
<input type = "submit" value = "Export as PDF" style="display:none" class="td_link pdf_button" name ="generate_report_pdf_btn" id = "generate_report_pdf_btn"/>
</div>
</g:form>
<div id = "html_report_section"></div>
答案 0 :(得分:3)
使用g:actionSubmit标记:
<g:form>
// your fields
<g:actionSubmit action="generateReport" value="Genereate Report" />
<g:actionSubmit action="exportAsPDF" value="Export as PDF" />
</g:form>
答案 1 :(得分:0)
您的原始问题未指明您希望表单提交为Ajax调用。要以相同的形式调用不同的Ajax操作,我使用了RemoteLink标记:
<g:form>
// your fields
<g:remoteLink action="generateReport" >Genereate Report</g:remoteLink>
<g:remoteLink action="exportAsPDF" >Export as PDF</g:remoteLink>
</g:form>
查看Grails文档,了解RemoteLink的其他属性和示例。