Given an ASP.NET MVC view that generates a table of entries using a ‘for’ loop, what is the best way to add a ‘delete’ link for each of the table rows? My first intuition would be to use jQuery to make an AJAX call to delete the row, then refresh the table. It seems like there should be an easier way though. Maybe make the link perform a post to a delete url (e.g. /Item/Delete/1) which would redirect back to the page displaying the items?
Share
both are acceptable ways, and actually exactly the same.
In the first you are using AJAX to post to the URL and AJAX to refresh the table. In the second, you are not using AJAX.
Either way, posting the id to be deleted to the delete ActionMethod (I’d use Destroy, but that’s personal preference) is the way to go.
To make it even better do something like this …