I am trying to implement a RESTful MVC project using C# and ASP.Net, accordingly I have a controller with methods distinguished by request types like this simplistic example:
[HttpGet, ActionName("Instance")]
public ActionResult Get(string id) {
//Get
}
[HttpPut, ActionName("Instance")]
public ActionResult Update(string id, Instance instance) {
//Update
}
[HttpDelete, ActionName("Instance")]
public ActionResult Delete(string id) {
//Delete
}
On the view I want to display the Instance and have buttons to update and delete which will invoke the appropriate actions above. What is the best way to create these buttons so that they generate a request with the appropriate request type?
This should help:
http://blog.osbornm.com/archive/2009/11/24/overriding-the-http-verb-in-asp.net-mvc-2.aspx
Additionally, for DELETE action (where you need only Id), you can have a different small form and use HttpMethodOverride method of html helper. See http://geekswithblogs.net/michelotti/archive/2010/01/08/implementing-a-delete-link-with-mvc-2-and-httpmethodoverride.aspx