在 Grails 中,如何从控制器返回到调用当前视图?
下面是一个非常简单的控制器,具有从 gsp 文件中的 g:submitButton 触发的“搜索”操作。我的问题是,如何返回包含调用此控制器搜索操作的提交按钮的视图,而不是重定向到“索引”操作和视图?
class DefaultSearchController {
def searchableService
def index = {
}
def search = {
def query = params.query
if(!query){
redirect(action:"index", params:params)
}
try{
def searchResults = searchableService.searchEvery( query )
redirect(action:"index", searchResults)
}
catch( e ){
params.errors = "${e.toString()}"
redirect(action: "index", params:params)
}
}
}
Below is a very simple controller with a "search" action that is fired from g:submitButton in a gsp file. My question is, instead of redirecting to the "index" action and view, how do I return to the view that contained the submit button that called this controller's search action?
class DefaultSearchController {
def searchableService
def index = {
}
def search = {
def query = params.query
if(!query){
redirect(action:"index", params:params)
}
try{
def searchResults = searchableService.searchEvery( query )
redirect(action:"index", searchResults)
}
catch( e ){
params.errors = "${e.toString()}"
redirect(action: "index", params:params)
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果要从不同的地方调用搜索操作,我将向其传递一个参数,告诉搜索控制器重定向到哪里或使用哪个视图呈现搜索结果。
干杯
李
If the search action is going to be called from various places, I would pass in a parameter to it telling search controller where to redirect to or which view to render the search results with.
cheers
Lee