User Id :    Password :      New Member   Forgot Password  
Delete with Dapper ORM and ASP.NET MVC 3
Description Delete with Dapper ORM and ASP.NET MVC 3   No. of Views     1856
  Rating     0
Author Jalpesh Vadgama   Posted On     04 Jun 2011

Sample Code   Download Code


I have been writing few posts about Dapper ORM and ASP.NET MVC3 for data manipulation. In this post I am going to explain how we can delete the data with Dapper ORM. For your reference following are the links my previous posts.

Playing with dapper Micro ORM and ASP.NET MVC 3.0

Insert with Dapper Micro ORM and ASP.NET MVC 3

Edit/Update with dapper ORM and ASP.NET MVC 3

So to delete customer we need to have delete method in Our CustomerDB class so I have delete method into the CustomerDB class like following.


public bool Delete(int customerId)
     using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring))
         string sqlQuery = "DELETE FROM [dbo].[Customer] WHERE CustomerId=@CustomerId";
         sqlConnection.Execute(sqlQuery, new {customerId});
     return true;
 catch (Exception exception)
     return false;

Now our delete method is ready It’s time to add ActionResult for Delete in Customer Controller like following. I have added two Action Result first will load simple delete with view and other action result will delete the data.

public ActionResult Delete(int id)
 var customerEntities = new CustomerDB();
 return View(customerEntities.GetCustomerByID(id));
// POST: /Customer/Delete/5
public ActionResult Delete(int id, FormCollection collection)
     var customerEntities = new CustomerDB();
     return RedirectToAction("Index");
     return View();

Now It’s time to add delete view. So I have added strongly typed view like following.

Now everything is ready with code. So it’s time to check functionality let’s run application with Ctrl + F5. It will load browser like following.

Now I am clicking on delete it will load following screen to confirm deletion.

Once you clicked delete button it will redirect back to customer list and record is delete as you can see in below screen.

So that’s it. Its very easy.. Hope you liked it.. Stay tuned for more..

kick it on

About Author

About Author I am jalpesh vadgama an Microsoft MVP for Visual C# and BrainBench Certified ASP.NET Developer having more then 5 years of experience in .NET Technology.Please feel free to contact me for any queries via posting comments on my blog I will try to reply as early as possible. Please also visit my blog at Jalpesh Vadgama
No Photo
Country India
Company N/A
Home Page

Rate this article

Rating options from poor, fair, good, very good to excelent.  


Write your comment here.
Verification Code