Question

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

Was it helpful?

Solution

Might as well bring the discussion in comments to an actual answer. Your code didn't compile because you had an extra @ in the argument.

As to why you're not hitting the DELETE end point is because you can't have a regular HTML link trigger a verb other than GET, and you can only submit forms to POST. If you want to invoke delete, you need to use JavaScript. For instance, you can use jQuery's ajax method with type set to "DELETE". In your case, you can create an onclick handler that in turn sends an ajax request. Also note, not all browsers support the DELETE verb like this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top