Best way to implement delete in ASP.NET MVC "gridview"?

Given an ASP.NET MVC view that generates a table of records using a "for" loop, what is the best way to add a "delete" link for each row of the table? My first intuition would be to use jQuery to make an AJAX call to delete a row and then update the table. It looks like there should be an easier way. Is it possible for the link to follow the message into a delete url (like / Item / Delete / 1) that would redirect back to the page displaying the items?

+1


source to share


1 answer


both are acceptable ways and in fact exactly the same.

In the first, you use AJAX to post to the url and AJAX to update the table. In the second case, you are not using AJAX.

Anyway, placing the id to be removed, remove the ActionMethod (I'd use Destroy, but that's personal preference) is the way to go.



To make something like this even better ...

[AcceptVerbs(HttpVerbs.Delete)]
    public ActionResult Detail (int id)
    {
        // Add action logic here

    }

      

+4


source







All Articles