朋友们下午好。
在过去的几天里,我一直在努力解决一个非常令人沮丧的问题,终于走到了尽头。我团队中每个有一点时间的人似乎也无法弄清楚这个问题,这让我发疯了!
无论如何,我有一个带有删除操作的控制器,当用户从引导模式对话框中确认删除时调用该操作。该操作被调用并且重定向语句在调试中被击中就好了。它甚至将 chrome 开发者工具中的调用显示为被调用!
但是,出于某种原因,页面永远不会重定向。我什至尝试在操作中没有其他代码的情况下明确重定向到 Google。我不知道这笔交易是什么。我会发布任何相关代码;如果您可能需要其他代码,请告诉我。
目录控制器.groovy
def delete = {
def catalog = Catalog.get(params.id)
if (catalog == null) {
redirect(controller: 'home', action: 'dashboard')
println "Catalog is null and cannot be Deleted"
return
}
if (request.method == "POST") {
//catalog.deleted = true TESTING UNTIL REDIRECT WORKS
if (catalog.validate()) {
userService.addUserActivity("Deleted catalog " + catalog.title, catalog.class.getName(), catalog.id, null)
flash.notice = "Catalog has been deleted"
catalog.save()
println "Catalog successfully deleted"
}
else {
flash.error = "There was an error marking the catalog deleted"
}
redirect(controller: 'home', action: 'dashboard')
return
}
[ catalog: catalog ]
}
Bootstrap 模态标记
<div id="deleteDialog" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
<h3 id="myModalLabel">Delete Catalog</h3>
</div>
<div class="modal-body">
<p><strong>Are you sure you want to delete this Catalog?</strong></p>
<div class="dialogInnerInfo">
<div class="row-fluid control-group">
<label class="control-label" for="catalogNumber">Catalog Number:</label>
<div class="controls">
<label id="catalogNumber" >${catalog.legacyId}</label>
<input type="hidden" name="id" value="${catalog.id}"/>
</div>
</div>
<div class="row-fluid control-group">
<label class="control-label" for="catalogTitle">Catalog Title:</label>
<div class="controls">
<label id="catalogTitle">${catalog.title}</label>
</div>
</div>
<div class="row-fluid control-group">
<label class="control-label" for="catalogTitle">Number of Samples:</label>
<div class="controls">
<label id="catalogTitle">${catalog.sampleCount}</label>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<g:remoteLink class="btn btn-primary" controller="catalog" action="delete" id="${catalog.id}" data-dismiss="modal">Yes</g:remoteLink>
<button class="btn btn-primary" value="${catalog.id}" data-dismiss="modal" onclick="${remoteFunction(action:'delete', controller: 'catalog', params: '\'id=\' + this.value')}">Click Here</button>
<button class="btn" data-dismiss="modal" aria-hidden="true">No</button>
</div>
</div>
我尝试了各种不同的按钮(g:links、buttons、g:remoteLinks 等)并清理了删除操作。我还尝试删除我的浏览器缓存、grails 缓存、运行 grails-clean 和其他任务,以查看问题是否在我的环境中,但其他人也没有得到重定向。
请原谅丑陋的编码,一旦重定向工作,它将被清理。我也欢迎提出建议和改进:)
非常感谢您的时间和帮助!