
282Microsoft Visual Studio 2010: A Beginner’s Guide
VB:
'
' GET: /Customer/Delete/5
Function Delete(ByVal id As Integer) As ActionResult Dim custRep As New CustomerRepository custRep.DeleteCustomer(id)
TempData("Result") = "Customer Deleted."
Return RedirectToAction("Index")
End Function
Besides showing how to use the repository for performing the delete operation, there are a couple of new items in Listing
In all of the other calls to View, it was assumed that a View named after the Controller method would be returned, so it wasn’t necessary to specify the name of the View. However, we don’t have a delete View, so we specify Index as the View explicitly.
To accommodate the delete operation, Listing
Listing 9-13 Deleting a Customer
C#:
... content removed
<h2>Index</h2>
<p>
<% if (TempData["Result"] != null) { %>
<label><%= Html.Encode(TempData["Result"].ToString() )%>
</label> <% } %>
</p>
<table>