In Focus

CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM

In this article, we will learn CRUD operation in ASP.NET Core 2.0 using Dapper ORM step by step. We will use Visual Studio 2017 to develop the web application using ASP.NET Core 2.0 with razor pages using Dapper. If you don’t have a basic idea of ASP.NET Core and how to set up ASP.NET Core Environment. How to install Visual Studio 2017. Then Please go with my previous article as follow.

In this article, we will learn CRUD operation in ASP.NET Core 2.0 using Dapper ORM, step by step.
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM 
 
We will use Visual Studio 2017 to develop the web application using ASP.NET Core 2.0 with Razor pages using Dapper. If you don’t have a basic idea of ASP.NET Core and how to set up ASP.NET Core Environment, then before proceeding further, please refer to my previous articles on ASP.NET Core 2.0 for a better understanding, as mentioned below.
Prerequisites 
What's Dapper?

Dapper is a simple object mapper for .NET and owns the title of "King of Micro ORM" in terms of speed. An ORM is an Object Relational Mapper, which is responsible for mapping between database and programming language.

There are three steps to working with Dapper as follows,
  • Create an IDbConnection object.
  • Write a query to perform CRUD operations.
  • Pass query as a parameter in Execute method.
More detail - dapper-tutorial

We will create one small "Group Meeting" web application using ASP.NET Core 2.0. using Dapper ORM as follow.
 
First of all, create database scripts.
 
Scripts 1
 
To create the database.
  1.  CREATE DATABASE ProjectMeeting    
Scripts 2
 
To create the database table named as “GroupMeeting”.
  1. USE [ProjectMeeting]  
  2. GO  
  3.   
  4. /****** Object:  Table [dbo].[GroupMeeting]    Script Date: 18-08-2018 23:02:42 ******/  
  5. SET ANSI_NULLS ON  
  6. GO  
  7.   
  8. SET QUOTED_IDENTIFIER ON  
  9. GO  
  10.   
  11. SET ANSI_PADDING ON  
  12. GO  
  13.   
  14. CREATE TABLE [dbo].[GroupMeeting](  
  15.     [Id] [int] IDENTITY(1,1) NOT NULL,  
  16.     [ProjectName] [varchar](50) NULL,  
  17.     [GroupMeetingLeadName] [varchar](50) NULL,  
  18.     [TeamLeadName] [varchar](50) NULL,  
  19.     [Description] [varchar](50) NULL,  
  20.     [GroupMeetingDate] [dateNULL,  
  21.  CONSTRAINT [PK_GroupMeeting-2] PRIMARY KEY CLUSTERED   
  22. (  
  23.     [Id] ASC  
  24. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ONON [PRIMARY]  
  25. ON [PRIMARY]  
  26.   
  27. GO  
  28.   
  29. SET ANSI_PADDING OFF  
  30. GO  
Scripts 3
 
Create the stored procedure to get all the group meeting details.
  1. Create procedure [dbo].[GetGroupMeetingDetails]    
  2. AS    
  3. BEGIN    
  4.      SELECT * FROM GROUPMEETING    
  5. END    
Scripts 4
 
Create the stored procedure to get the group meeting by Id.
  1. Create procedure [dbo].[GetGroupMeetingByID](@Id int)    
  2. AS    
  3. BEGIN    
  4.      SELECT * FROM GROUPMEETING where id=@Id    
  5. END    
Scripts 5
 
Create the stored procedure to create a new group meeting,
  1. create procedure [dbo].[InsertGroupMeeting]    
  2. (    
  3.     @ProjectName varchar(50),    
  4.     @GroupMeetingLeadName varchar(50),    
  5.     @TeamLeadName varchar(50),    
  6.     @Description varchar(50),    
  7.     @GroupMeetingDate date    
  8. )    
  9. As    
  10. BEGIN    
  11.     
  12.  INSERT INTO GroupMeeting(ProjectName,GroupMeetingLeadName,TeamLeadName,Description,GroupMeetingDate)    
  13.  VALUES(@ProjectName,@GroupMeetingLeadName,@TeamLeadName,@Description,@GroupMeetingDate)    
  14.     
  15. END    
Scripts 6
 
Create the stored procedure to update the group meeting.
  1. create procedure [dbo].[UpdateGroupMeeting]    
  2. (    
  3.     @Id int,    
  4.     @ProjectName varchar(50),    
  5.     @GroupMeetingLeadName varchar(50),    
  6.     @TeamLeadName varchar(50),    
  7.     @Description varchar(50),    
  8.     @GroupMeetingDate date    
  9. )    
  10. As    
  11. BEGIN    
  12.      UPDATE GroupMeeting    
  13.      SET ProjectName =@ProjectName,    
  14.      GroupMeetingLeadName =@GroupMeetingLeadName,    
  15.      TeamLeadName = @TeamLeadName,    
  16.      Description = @Description,    
  17.      GroupMeetingDate =@GroupMeetingDate    
  18.      Where Id=@Id    
  19. END    
Scripts 7
 
Create the stored procedure to delete the group meeting. 
  1. create procedure [dbo].[DeleteGroupMeeting]    
  2. (    
  3.     @Id int     
  4. )    
  5. As    
  6. BEGIN    
  7.     DELETE FROM GroupMeeting WHERE Id=@Id    
  8. END   
To Insert dummy records into the database table execute the following scripts.
  1. USE [ProjectMeeting]  
  2. GO  
  3.   
  4. INSERT INTO [dbo].[GroupMeeting]  
  5.            ([ProjectName]  
  6.            ,[GroupMeetingLeadName]  
  7.            ,[TeamLeadName]  
  8.            ,[Description]  
  9.            ,[GroupMeetingDate])  
  10.      VALUES  
  11.            ('Online Laptop booking',  
  12.            'Madhav S',  
  13.            'Kishor D',  
  14.            'Online Laptop booking Software',  
  15.            GETDATE()),  
  16.           ('Internal Interprice Commnumication',  
  17.            'Abhijit L',  
  18.            'Dnyanesh D',  
  19.            'Interprice Commnumication',  
  20.            GETDATE()),  
  21.            ('Health Care Management',  
  22.            'Jon M',  
  23.            'Randy L',  
  24.            'Health Care management project',  
  25.            GETDATE())  
  26. GO  
Now, we have completed our database related changes. Let’s we can go with code base changes using Visual Studio 2017.
 
Step 1
 
Open the Visual Studio 2017.

CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM
 
Step 2
 
Click on File => Open => New Project as shown in the image. 

CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM
 
Step 3
 
Select .NET Core from the left side and select the ‘ASP.NET Core Web Application’ from the new open project template. Then provide the meaning name like “GroupMeetingASP.NETCoreWebApp”.
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM
 
Step 4
 
Select Web Application(MVC) template from the list of templates and click on "OK" button as follow.
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM
 
Step 5
 
The default ASP.NET Core MVC structure gets created as follow. The default model, view, controller gets created by default.
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM
  
Step 6
 
Right click on Models => Click on Add => Click on Class.
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM
 
Step 7
 
Provide a meaningful name like “GroupMeeting” and click on "Add" button as follow.
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM
 
To work with dapper we need to install dapper ORM using 'Manage Nuget Package' 
  1. Right click on Solution Manager => Click on 'Manage Nuget Package' as shown in the figure.

    CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM

  2. Select 'Browse' and type dapper in the search box => Enter =>Select the dapper and Click on Install as shown in the figure.
 CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM
 
  After successful installation of dapper ORM:
 
 CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM
 
In order to work with Dapper ORM we need to import a namespace as follows.
  1. using Dapper;  
Step 8
 
Write code to create properties for group meeting class as follow. Also, use the Required attribute to validate the class fields.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Data;  
  5. using System.Data.SqlClient;  
  6. using System.ComponentModel.DataAnnotations;  
  7. using Dapper;  
  8.   
  9. namespace GroupMeetingASP.NETCoreWebApp.Models  
  10. {  
  11.     public class GroupMeeting  
  12.     {          
  13.         public int Id { getset; }  
  14.   
  15.         [Required(ErrorMessage ="Enter Project Name!")]  
  16.         public string ProjectName { getset; }  
  17.   
  18.         [Required(ErrorMessage = "Enter Group Lead Name!")]  
  19.         public string GroupMeetingLeadName { getset; }  
  20.   
  21.         [Required(ErrorMessage = "Enter Team Lead Name!")]  
  22.         public string TeamLeadName { getset; }  
  23.   
  24.         [Required(ErrorMessage = "Enter Description!")]  
  25.         public string Description { getset; }  
  26.   
  27.         [Required(ErrorMessage = "Enter Group Meeting Date!")]  
  28.         public DateTime GroupMeetingDate { getset; }  
  29.   
  30.         static string strConnectionString = "User Id=sa;Password=Shri;Server=DESKTOP-2D0R2UP\\SQL2014;Database=ProjectMeeting;";  
  31.   
  32. }  
Step 9
 
Write code to get all group meeting detail from the database using the stored procedure with dapper ORM. The method name is "GetGroupMeetings()" and return type is IEnumerable<GroupMeeting> or List<GroupMeeting> you can use either one of them.
  1. public static IEnumerable<GroupMeeting> GetGroupMeetings()  
  2.         {  
  3.             List<GroupMeeting> groupMeetingsList = new List<GroupMeeting>();  
  4.   
  5.             using (IDbConnection con = new SqlConnection(strConnectionString))  
  6.             {  
  7.                 if (con.State == ConnectionState.Closed)  
  8.                     con.Open();  
  9.   
  10.                 groupMeetingsList = con.Query<GroupMeeting>("GetGroupMeetingDetails").ToList();  
  11.             }  
  12.              
  13.             return groupMeetingsList;  
  14.         }  
Get group meeting details by groupId code as follow,
  1. public static GroupMeeting GetGroupMeetingById(int? id)  
  2.         {  
  3.             GroupMeeting groupMeeting = new GroupMeeting();  
  4.             if (id == null)  
  5.                 return groupMeeting;  
  6.   
  7.             using (IDbConnection con = new SqlConnection(strConnectionString))  
  8.             {  
  9.                 if (con.State == ConnectionState.Closed)  
  10.                     con.Open();  
  11.   
  12.                 DynamicParameters parameter = new DynamicParameters();  
  13.                 parameter.Add("@Id", id);  
  14.                 groupMeeting = con.Query<GroupMeeting>("GetGroupMeetingByID", parameter, commandType:CommandType.StoredProcedure).FirstOrDefault();  
  15.             }  
  16.                           
  17.             return groupMeeting;  
  18.         }  
Step 10
 
The code to insert the group meeting using dapper is as follows. The method name is 'AddGroupMeeting()' an integer return type.
  1. public static int AddGroupMeeting(GroupMeeting groupMeeting)  
  2.         {  
  3.             int rowAffected = 0;  
  4.             using (IDbConnection con = new SqlConnection(strConnectionString))  
  5.             {  
  6.                 if (con.State == ConnectionState.Closed)  
  7.                     con.Open();  
  8.   
  9.                 DynamicParameters parameters = new DynamicParameters();  
  10.                 parameters.Add("@ProjectName", groupMeeting.ProjectName);  
  11.                 parameters.Add("@GroupMeetingLeadName", groupMeeting.GroupMeetingLeadName);  
  12.                 parameters.Add("@TeamLeadName", groupMeeting.TeamLeadName);  
  13.                 parameters.Add("@Description", groupMeeting.Description);  
  14.                 parameters.Add("@GroupMeetingDate", groupMeeting.GroupMeetingDate);  
  15.   
  16.                 rowAffected= con.Execute("InsertGroupMeeting",parameters,commandType:CommandType.StoredProcedure);  
  17.             }  
  18.              
  19.             return rowAffected;  
  20.         }  
Code to Update the group meeting using dapper is as follows.
  1. public static int UpdateGroupMeeting(GroupMeeting groupMeeting)  
  2.         {  
  3.             int rowAffected = 0;  
  4.   
  5.             using (IDbConnection con = new SqlConnection(strConnectionString))  
  6.             {  
  7.                 if (con.State == ConnectionState.Closed)  
  8.                     con.Open();  
  9.   
  10.                 DynamicParameters parameters = new DynamicParameters();  
  11.                 parameters.Add("@Id", groupMeeting.Id);  
  12.                 parameters.Add("@ProjectName", groupMeeting.ProjectName);  
  13.                 parameters.Add("@GroupMeetingLeadName", groupMeeting.GroupMeetingLeadName);  
  14.                 parameters.Add("@TeamLeadName", groupMeeting.TeamLeadName);  
  15.                 parameters.Add("@Description", groupMeeting.Description);  
  16.                 parameters.Add("@GroupMeetingDate", groupMeeting.GroupMeetingDate);  
  17.               rowAffected=  con.Execute("UpdateGroupMeeting",parameters,commandType:CommandType.StoredProcedure);  
  18.             }  
  19.                           
  20.             return rowAffected;  
  21.         }  
Code to delete the group meeting using dapper is as follows. 
  1. public static int DeleteGroupMeeting(int id)  
  2.         {  
  3.             int rowAffected = 0;  
  4.             using (IDbConnection con = new SqlConnection(strConnectionString))  
  5.             {  
  6.                 if (con.State == ConnectionState.Closed)  
  7.                     con.Open();  
  8.                 DynamicParameters parameters = new DynamicParameters();  
  9.                 parameters.Add("@Id",id);  
  10.                 rowAffected = con.Execute("DeleteGroupMeeting",parameters,commandType:CommandType.StoredProcedure);  
  11.   
  12.             }  
  13.                          
  14.             return rowAffected;  
  15.         }  
As of now, we have completed the model related changes Get, Insert, Update, Delete using dapper ORM in the above code.
 
Step 11
 
Right click on Controller folder => Click on “Add” => Click on Controller as follows. 
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM 
 
Step 12
 
Select MVC Controller Empty and click on add button as follows.
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM 
 
Provide a meaningful name like “GroupMeeting” as follows.
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM 
Step 13
 
After adding the controller, you need to import the required namespace. Then added the following code to get all group meeting details and pass to the view as follow. 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Threading.Tasks;  
  5. using Microsoft.AspNetCore.Mvc;  
  6. using GroupMeetingASP.NETCoreWebApp.Models;  
  7.   
  8. namespace GroupMeetingASP.NETCoreWebApp.Controllers  
  9. {  
  10.     public class GroupMeetingController : Controller  
  11.     {  
  12.         public IActionResult Index()  
  13.         {  
  14.             return View(GroupMeeting.GetGroupMeetings());  
  15.         }  
  16.     }  
  17. }  
Step 14
 
Right click on ActionResult and click on Add view as follow.
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM 
 
Step 15
 
Write code for displaying group meeting data on Index.cshtml view as follows. 
  1. @model IEnumerable<GroupMeetingASP.NETCoreWebApp.Models.GroupMeeting>  
  2. @{  
  3.     ViewData["Title"] = "Index";  
  4. }  
  5.   
  6. <h4>Group Meeting Web App</h4><hr />  
  7. <h4>  
  8.     <a asp-action="AddGroupMeeting">Add GroupMeeting</a>  
  9. </h4>  
  10. <div>  
  11.     <table class="table table-responsive table-bordered panel-primary">  
  12.         <thead>  
  13.             <th>Project Name</th>  
  14.             <th>Group Lead Name</th>  
  15.             <th>Team Lead Name</th>  
  16.             <th>Description</th>  
  17.             <th>Meeting Date</th>  
  18.         <th></th>  
  19.         </thead>  
  20.         <tbody>  
  21.             @foreach (var item in Model)  
  22.             {   
  23.             <tr>  
  24.                 <td>@Html.DisplayFor(model => item.ProjectName)</td>  
  25.                 <td>@Html.DisplayFor(model => item.GroupMeetingLeadName)</td>  
  26.                 <td>@Html.DisplayFor(model => item.TeamLeadName)</td>  
  27.                 <td>@Html.DisplayFor(model => item.Description)</td>  
  28.                 <td>@Html.DisplayFor(model => item.GroupMeetingDate)</td>  
  29.                 <td>  
  30.                     <a asp-action="EditMeeting" asp-route-id="@item.Id">Edit</a>|  
  31.                     <a asp-action="DeleteMeeting" asp-route-id="@item.Id">Delete</a>  
  32.                 </td>  
  33.             </tr>  
  34.   
  35.             }  
  36.         </tbody>  
  37.     </table>  
  38. </div> 
Click on Startup.cs file and change the Controller name to "GroupMeeting" controller as follows.
  1. app.UseMvc(routes =>  
  2.            {  
  3.                routes.MapRoute(  
  4.                    name: "default",  
  5.                    template: "{controller=GroupMeeting}/{action=Index}/{id?}");  
  6.            });  
After changing the controller name in startup.cs file click on IIS Express to run the application OR F5.
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM 
 
Index page display is as follows. 
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM 
Step 16
 
We will create “AddGroupMeeting” view in the GroupMeeting controller and write the following code. We have written two views, "HttpGet" and "HttpPost" as follows.
  1. [HttpGet]  
  2.       public IActionResult AddGroupMeeting()  
  3.       {  
  4.           return View();  
  5.       }  
  6.   
  7.       [HttpPost]  
  8.       public IActionResult AddGroupMeeting([Bind] GroupMeeting groupMeeting)  
  9.       {  
  10.           if (ModelState.IsValid)  
  11.           {  
  12.               if (GroupMeeting.AddGroupMeeting(groupMeeting) > 0)  
  13.               {  
  14.                   return RedirectToAction("Index");  
  15.               }  
  16.           }  
  17.           return View(groupMeeting);  
  18.       }  
Step 17
 
We will create “AddGroupMeeting.cshtml” view and write the code to add the group meeting detail as follows.
  1. @model GroupMeetingASP.NETCoreWebApp.Models.GroupMeeting  
  2. @{  
  3.     ViewData["Title"] = "AddGroupMeeting";  
  4. }  
  5.   
  6. <h2>Add Group Meeting</h2>  
  7. <div class="row">  
  8.     <div class="col-md-4">  
  9.         <form asp-action="AddGroupMeeting">  
  10.             <div class="">  
  11.                 <label asp-for="ProjectName" class="control-label"></label>  
  12.                 <input asp-for="ProjectName" class="form-control" />  
  13.                 <span class="alert-danger" asp-validation-for="ProjectName"></span>  
  14.             </div>  
  15.             <div class="form-group">  
  16.                 <label asp-for="GroupMeetingLeadName" class="control-label"></label>  
  17.                 <input asp-for="GroupMeetingLeadName" class="form-control" />  
  18.                 <span class="alert-danger" asp-validation-for="GroupMeetingLeadName"></span>  
  19.             </div>  
  20.             <div class="form-group">  
  21.                 <label asp-for="TeamLeadName" class="control-label"></label>  
  22.                 <input asp-for="TeamLeadName" class="form-control" />  
  23.                 <span class="alert-danger" asp-validation-for="TeamLeadName"></span>  
  24.             </div>  
  25.             <div class="form-group">  
  26.                 <label asp-for="Description" class="control-label"></label>  
  27.                 <input asp-for="Description" class="form-control" />  
  28.                 <span class="alert-danger" asp-validation-for="Description"></span>  
  29.             </div>  
  30.             <div class="form-group">  
  31.                 <label asp-for="GroupMeetingDate" class="control-label"></label>  
  32.                 <input asp-for="GroupMeetingDate" class="form-control" />  
  33.                 <span class="alert-danger" asp-validation-for="GroupMeetingDate"></span>  
  34.             </div>  
  35.             <div class="form-group">  
  36.                 <input type="submit" value="Create Meeting" class="btn btn-success btn-sm" />  
  37.             </div>             
  38.         </form>  
  39.     </div>  
  40.     <div class="col-md-8">  
  41.   
  42.     </div>  
  43. </div>  
  44. <div>  
  45.     <a asp-action="Index">Back To Home</a>  
  46. </div>  
 "AddGroupMeeting" view display as follows.
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM 
 
 We have also added the validation using DataAnnotations on the add group meeting page.
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM 
 
Enter the valid information in the group meeting page and click on “Create Meeting” button. Then it will redirect to the index view page.
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM
Step 18
 
We will create “EditMeeting” view in the GroupMeeting Controller and write the code to edit the group meeting detail as follows.
There are two views of EditMeeting "HttpGet" and "HttpPost". The "HttpGet" edit meeting view has id as a parameter and gets called when clicking on "Edit" button on index view page.
  1. [HttpGet]  
  2.         public IActionResult EditMeeting(int? id)  
  3.         {  
  4.             if (id == null)  
  5.             {  
  6.                 return NotFound();  
  7.             }  
  8.             GroupMeeting group = GroupMeeting.GetGroupMeetingById(id);  
  9.             if (group == null)  
  10.                 return NotFound();  
  11.             return View(group);  
  12.         }  
  13.   
  14.         [HttpPost]  
  15.         public IActionResult EditMeeting(int id, [Bind] GroupMeeting groupMeeting)  
  16.         {  
  17.             if (id != groupMeeting.Id)  
  18.                 return NotFound();  
  19.   
  20.             if (ModelState.IsValid)  
  21.             {  
  22.                 GroupMeeting.UpdateGroupMeeting(groupMeeting);  
  23.                 return RedirectToAction("Index");  
  24.             }  
  25.             return View(groupMeeting);  
  26.         }  
We will create “EditMeeting.cshtml” view and write the code as follows.
  1. @model GroupMeetingASP.NETCoreWebApp.Models.GroupMeeting  
  2. @{  
  3.     ViewData["Title"] = "EditMeeting";  
  4. }  
  5. <h4>Update the Meeting</h4>  
  6. <div class="row">  
  7.     <div class="col-md-4">  
  8.         <form asp-action="EditMeeting">  
  9.             <input type="hidden" asp-for="Id" />  
  10.             <div class="form-group">  
  11.                 <label asp-for="ProjectName" class="control-label"></label>  
  12.                 <input asp-for="ProjectName" class="form-control" />  
  13.             </div>  
  14.             <div class="form-group">  
  15.                 <label asp-for="GroupMeetingLeadName" class="control-label"></label>  
  16.                 <input asp-for="GroupMeetingLeadName" class="form-control" />  
  17.             </div>  
  18.             <div class="form-group">  
  19.                 <label asp-for="TeamLeadName" class="control-label"></label>  
  20.                 <input asp-for="TeamLeadName" class="form-control" />  
  21.             </div>  
  22.             <div class="form-group">  
  23.                 <label asp-for="Description" class="control-label"></label>  
  24.                 <input asp-for="Description" class="form-control" />  
  25.             </div>  
  26.             <div class="form-group">  
  27.                 <label asp-for="GroupMeetingDate" class="control-label"></label>  
  28.                 <input asp-for="GroupMeetingDate" class="form-control" />  
  29.             </div>  
  30.             <div class="form-group">  
  31.                 <input type="submit" value="Edit Meeting" class="btn btn-success btn-sm" />  
  32.             </div>  
  33.         </form>  
  34.     </div>  
  35.     <div class="col-md-8">  
  36.   
  37.     </div>  
  38. </div>  
  39. <div>  
  40.     <a asp-action="Index">Back To Home</a>  
  41. </div>  
Click on "Edit" button on the index view page as follows.
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM 
 
It will open the following page when you click on the "edit" button. Then the group meeting will get updated into the database and redirected to the index view page.
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM 
Change the group meeting detail as per your requirement and click on "Edit Meeting" button to update the group meeting details. It will update the group meeting detail and redirect to the home page.
 
Step 19
 
We will create “DeleteMeeting” view in the GroupMeeting Controller and write the code to delete the group meeting detail as follows.
There are two views of DeleteMeeting "HttpGet" and "HttpPost" as follow. 
  1. public IActionResult DeleteMeeting(int id)  
  2.         {  
  3.             GroupMeeting group = GroupMeeting.GetGroupMeetingById(id);  
  4.             if (group==null)  
  5.             {  
  6.                 return NotFound();  
  7.             }  
  8.   
  9.             return View(group);  
  10.         }  
  11.         [HttpPost]  
  12.         public IActionResult DeleteMeeting(int id,GroupMeeting groupMeeting)  
  13.         {  
  14.             if (GroupMeeting.DeleteGroupMeeting(id) > 0)  
  15.             {  
  16.                 return RedirectToAction("Index");  
  17.             }  
  18.             return View(groupMeeting);  
  19.         }  
Step 20
 
Write the “DeleteMeeting.cshtml” view page code as mentioned below.
  1. @model GroupMeetingASP.NETCoreWebApp.Models.GroupMeeting  
  2. @{  
  3.     ViewData["Title"] = "DeleteMeeting";  
  4. }  
  5.   
  6. <h3 class="alert">Are you sure you want to delete this?</h3>  
  7. <div>  
  8.     <dl class="dl-horizontal">  
  9.         <dt>  
  10.             @Html.DisplayNameFor(model => model.ProjectName)  
  11.         </dt>  
  12.         <dd>  
  13.             @Html.DisplayFor(model => model.ProjectName)  
  14.         </dd>  
  15.         <dt>  
  16.             @Html.DisplayNameFor(model => model.GroupMeetingLeadName)  
  17.         </dt>  
  18.         <dd>  
  19.             @Html.DisplayFor(model => model.GroupMeetingLeadName)  
  20.         </dd>  
  21.         <dt>  
  22.             @Html.DisplayNameFor(model => model.TeamLeadName)  
  23.         </dt>  
  24.         <dd>  
  25.             @Html.DisplayFor(model => model.TeamLeadName)  
  26.         </dd>  
  27.         <dt>  
  28.             @Html.DisplayNameFor(model => model.Description)  
  29.         </dt>  
  30.         <dd>  
  31.             @Html.DisplayFor(model => model.Description)  
  32.         </dd>  
  33.         <dt>  
  34.             @Html.DisplayNameFor(model => model.GroupMeetingDate)  
  35.         </dt>  
  36.         <dd>  
  37.             @Html.DisplayFor(model => model.GroupMeetingDate)  
  38.         </dd>  
  39.     </dl>  
  40.   
  41.     <form asp-action="DeleteMeeting">  
  42.         <input type="hidden" asp-for="Id" />  
  43.         <input type="submit" value="YES" class="btn btn-danger btn-sm" /> <a asp-action="Index" class="btn btn-danger">NO</a>  
  44.     </form>  
  45. </div>    
Run the application. The defualt index view page will open. Then, click on the "Delete" link as follows.
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM
 
After clicking on the “delete” button on the Index View page, the following page will open for confirmation to delete the group meeting.
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM 
After that, click on “Yes” button. The selected group meeting will get deleted from the list of group meetings and the page will redirect to the Index View page which will look like this.
 
CRUD Operation In ASP.NET Core 2.0 Using Dapper ORM 
 
I hope you understand the basic concepts of CRUD operation using ASP.NET Core 2.0 with Razor View pages using Dapper ORM.