0

Item is a model class and Items is a controller class. Now I am trying to use reverse routing with parameter, but it fails. How to fix it?

view:

@(item: Item)

<a href="@routes.Items.delete(@item.id)">delete</a>

routes:

GET     /items/$id<[0-9]+>           controllers.Items.show(id: Long)
GET     /items/add                  controllers.Fruits.addForm()
POST    /items/add                  controllers.Items.add()
DELETE  /items/$id<[0-9]+>           controllers.Fruits.delete(id: Long)

error which I get

illegal start of simple expression

and it points at second @ character

4

1 回答 1

3

不妨将评论中的讨论带入实际答案。您的代码没有编译,因为您@在参数中有一个额外的内容。

至于为什么您没有达到 DELETE 端点是因为您不能让常规 HTML 链接触发除 GET 之外的动词,并且您只能将表单提交给 POST。如果要调用删除,则需要使用 JavaScript。例如,您可以使用ajax类型设置为 jQuery 的方法"DELETE"。在您的情况下,您可以创建一个onclick处理程序,该处理程序反过来发送一个 ajax 请求。另请注意,并非所有浏览器都支持这样的 DELETE 动词。

于 2013-09-27T22:10:36.243 回答