Chapter 9: Creating Web Applications with ASP.NET MVC | 281 |
Return RedirectToAction("Index")
Catch
Return View()
End Try
End Function
In the get Edit action method, you need to get a reference to the current record, indicated by the id being passed in, and pass that reference to the View for display. The post Edit action method accepts the modified customer and passes it to the repository for update in the database. You should also
The final operation to complete is discussed next, how to delete a Customer.
Deleting a Customer
The default template for creating a list added an ActionLink for Details, next to the Edit ActionLink. You can create a
Listing 9-12 The Delete Controller method
C#:
//
// GET: /Customer/Delete/5
public ActionResult Delete(int id)
{
new CustomerRepository()
.DeleteCustomer(id);
TempData["Result"] = "Customer Deleted.";
return RedirectToAction("Index");
}