【问题标题】:Delete a row using allowed method from grails link in grails使用允许的方法从 grails 中的 grails 链接中删除一行
【发布时间】:2015-11-16 01:09:57
【问题描述】:

我正在使用 grails 2.4.2。我有一个表单,我可以在其中添加、编辑或删除任何数据或行。但是我想从索引中按需删除一行。为此,我在表格单元格中为每一行添加了一个链接。但它给出了错误号 405,即The specified HTTP method is not allowed for the requested resource。谁能帮我解决这个问题?以下是我的索引页:

我的 index.gsp >>>

<table>
        <thead>
                <tr>                    
                    <g:sortableColumn property="address" title="${message(code: 'userInfo.address.label', default: 'Address')}" />                  
                    <g:sortableColumn property="name" title="${message(code: 'userInfo.name.label', default: 'Name')}" />
                    <g:sortableColumn property="name" title="${message(code: 'userInfo.name.label', default: 'Action')}" />
                </tr>
            </thead>
            <tbody>
            <g:each in="${userInfoInstanceList}" status="i" var="userInfoInstance">
                <tr class="${(i % 2) == 0 ? 'even' : 'odd'}">                   
                    <td><g:link action="show" id="${userInfoInstance.id}">${fieldValue(bean: userInfoInstance, field: "address")}</g:link></td>                 
                    <td>${fieldValue(bean: userInfoInstance, field: "name")}</td>
                    <td><g:link action="delete" id="${userInfoInstance.id}">Delete</g:link></td>                    
                </tr>
            </g:each>
            </tbody>
        </table>

【问题讨论】:

    标签: grails grails-2.0


    【解决方案1】:

    我认为您在控制器中使用“allowedMethods”,就像这样

        static allowedMethods = [delete: "POST"]
    

    http://grails.github.io/grails-doc/2.4.2/ref/Controllers/allowedMethods.html

    但是当您使用链接标签库时,您正在发出 GET 请求而不是 POST

    【讨论】:

    • 感谢您的回复。我允许的方法是这样的static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]。我的问题是,我可以使用 delete: DELETE 和 g:link 标签吗?!!!
    • 不,你不能。您必须使用 AJAX 或需要使用 DELETE 方法提交表单
    猜你喜欢
    • 2013-08-09
    • 2012-04-30
    • 2023-03-12
    • 2014-03-14
    • 2015-11-30
    • 1970-01-01
    • 1970-01-01
    • 2011-03-08
    • 1970-01-01
    相关资源
    最近更新 更多