CRUD Operation Using Repository Design Pattern In ASP.NET MVC

Introduction

 
This article will explain the repository design pattern in ASP.NET MVC. We will discuss CRUD (Create, Update, Read and Delete) operations using Repository Design Pattern in ASP.NET MVC. The Repository Design Pattern in C# is one of the most used design patterns in real-time applications.
 
Nowadays, most of the data-driven applications need to access the data residing in one or more other data sources. The easiest or simplest approach is to write all the data access related code in the main application itself.

 
Repository Design Pattern in C#

 
The Repository Design Pattern in C# works as a mediator between the domain and the data mapping layers using a collection-like interface for accessing the domain objects.
 
In other words, we can say that a Repository Design Pattern acts as a bridge between the rest of the application and the data access logic. That means a repository pattern isolates all the data access code from the rest of the application. The advantage of doing so is that if you need to make any change, then you have to do that only once in one place. Another benefit is that testing your controllers becomes easy because the testing framework needs not run against the actual database access code with a Repository Design Pattern introduced.
 
Let's see this with a demo application. 
 
Step 1 
 
Open SQL Server and create a database table to perform CRUD.
  1. CREATE TABLE [dbo].[Employee](  
  2.     [Id] [int] IDENTITY(1,1) NOT NULL,  
  3.     [FirstName] [nvarchar](50) NULL,  
  4.     [LastName] [nvarchar](50) NULL,  
  5.     [Age] [intNULL,  
  6.     [Position] [nvarchar](50) NULL,  
  7.     [Office] [nvarchar](50) NULL,  
  8.     [Salary] [intNULL,  
  9.  CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED   
  10. (  
  11.     [Id] ASC  
  12. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ONON [PRIMARY]  
  13. ON [PRIMARY]  
  14.   
  15. GO  
Step 2
 
Open Visual Studio 2015 or a version of your choice and create a new project.
 
Step 3
 
Choose web application project and give the appropriate name to your project.
 
CURD Operation Using Repository Design Pattern In ASP.NET MVC
 
Step 4
 
Select "empty template", check on MVC checkbox, and click OK.
 
CURD Operation Using Repository Design Pattern In ASP.NET MVC
 
Step 5 
 
Right-click the Models folder and add a database model. Add Entity Framework now. For that, right-click on Models folder, select Add, then select New Item.
 
CURD Operation Using Repository Design Pattern In ASP.NET MVC
 
You will get a window; from there, select Data from the left panel and choose ADO.NET Entity Data Model, give it the name EmployeeModel (this name is not mandatory, you can give any name) and click "Add".
 
CURD Operation Using Repository Design Pattern In ASP.NET MVC
 
After you click on "Add a window", the wizard will open. Choose EF Designer from the database and click "Next".
 
CURD Operation Using Repository Design Pattern In ASP.NET MVC
 
After clicking on "Next", a window will appear. Choose New Connection. Another window will appear. Add your server name - if it is local, then enter a dot (.). Choose your database and click "OK".
 
CURD Operation Using Repository Design Pattern In ASP.NET MVC
 
The connection will be added. If you wish, save the connection name as you want. You can change the name of your connection below. It will save the connection in the web config. Now, click "Next".
 
CURD Operation Using Repository Design Pattern In ASP.NET MVC
 
After clicking on Next, another window will appear. Choose the database table name as shown in the below screenshot and click "Finish".
 
CURD Operation Using Repository Design Pattern In ASP.NET MVC
 
Entity Framework gets added and the respective class gets generated under the Models folder.
 
CURD Operation Using Repository Design Pattern In ASP.NET MVC
 
Employee class
  1. using System.ComponentModel.DataAnnotations;  
  2.    
  3. namespace MvcRepositoryDesignPattern_Demo.Models  
  4. {  
  5.     using System;  
  6.     using System.Collections.Generic;  
  7.       
  8.     public partial class Employee  
  9.     {  
  10.         public int Id { getset; }  
  11.    
  12.         [Required(ErrorMessage = "Please enter first name")]  
  13.         [Display(Name="First Name")]  
  14.         public string FirstName { getset; }  
  15.    
  16.         [Required(ErrorMessage = "Please enter last name")]  
  17.         [Display(Name = "Last Name")]  
  18.         public string LastName { getset; }  
  19.    
  20.         [Required(ErrorMessage = "Please enter age")]  
  21.         public Nullable<int> Age { getset; }  
  22.    
  23.         [Required(ErrorMessage = "Please enter position")]  
  24.         public string Position { getset; }  
  25.    
  26.         [Required(ErrorMessage = "Please enter office")]  
  27.         public string Office { getset; }  
  28.    
  29.         [Required(ErrorMessage = "Please enter salary")]  
  30.         public Nullable<int> Salary { getset; }  
  31.     }  
  32. }  
Step 6
 
Right-click on project >> “Add” a folder >> name it Repositories.
 
Step 7
 
Right-click on created Repositories folder and “Add” an interface. Name it as IEmployeeRepository.cs. Write the following code.
  1. using MvcRepositoryDesignPattern_Demo.Models;  
  2. using System;  
  3. using System.Collections.Generic;  
  4. using System.Linq;  
  5. using System.Text;  
  6. using System.Threading.Tasks;  
  7.    
  8. namespace MvcRepositoryDesignPattern_Demo.Repositories  
  9. {  
  10.     public interface IEmployeeRepository  
  11.     {  
  12.         IEnumerable<Employee> GetEmployees();  
  13.         Employee GetEmployeeById(int id);  
  14.         void NewEmployee(Employee employee);  
  15.         void UpdateEmployee(Employee employee);  
  16.         void DeleteEmployee(int id);  
  17.         void Save();  
  18.     }  
  19. }  
Step 8
 
Similarly, add another class and name it EmployeeRepository.cs. Write the following code in it.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using MvcRepositoryDesignPattern_Demo.Models;  
  6. using System.Data.Entity;  
  7.    
  8. namespace MvcRepositoryDesignPattern_Demo.Repositories  
  9. {  
  10.     public class EmployeeRepository : IEmployeeRepository  
  11.     {  
  12.         private readonly EmployeeContext _dbContext;  
  13.    
  14.         public EmployeeRepository()  
  15.         {  
  16.             _dbContext = new EmployeeContext();  
  17.         }  
  18.         public EmployeeRepository(EmployeeContext context)  
  19.         {  
  20.             _dbContext = context;  
  21.         }  
  22.    
  23.         public IEnumerable<Employee> GetEmployees()  
  24.         {  
  25.             return _dbContext.Employees.ToList();  
  26.         }  
  27.    
  28.         public Employee GetEmployeeById(int id)  
  29.         {  
  30.             return _dbContext.Employees.Find(id);  
  31.         }  
  32.    
  33.         public void NewEmployee(Employee employee)  
  34.         {  
  35.             _dbContext.Employees.Add(employee);  
  36.             Save();  
  37.         }  
  38.    
  39.         public void UpdateEmployee(Employee employee)  
  40.         {  
  41.             _dbContext.Entry(employee).State = EntityState.Modified;  
  42.         }  
  43.    
  44.         public void DeleteEmployee(int id)  
  45.         {  
  46.             var employee = _dbContext.Employees.Find(id);  
  47.             if (employee != null) _dbContext.Employees.Remove(employee);  
  48.         }  
  49.                       
  50.         public void Save()  
  51.         {  
  52.             _dbContext.SaveChanges();  
  53.         }  
  54.    
  55.         private bool _disposed = false;  
  56.    
  57.         protected virtual void Dispose(bool disposing)  
  58.         {  
  59.             if (!this._disposed)  
  60.             {  
  61.                 if (disposing)  
  62.                 {  
  63.                     _dbContext.Dispose();  
  64.                 }  
  65.             }  
  66.             this._disposed = true;  
  67.         }  
  68.         public void Dispose()  
  69.         {  
  70.             Dispose(true);  
  71.             GC.SuppressFinalize(this);  
  72.         }  
  73.     }  
  74. }  
Step 9
 
Right-click on the Controllers folder and add a new controller.
 
CURD Operation Using Repository Design Pattern In ASP.NET MVC
 
A window will appear. Choose MVC5 Controller-Empty and click "Add".
 
CURD Operation Using Repository Design Pattern In ASP.NET MVC
 
After clicking on "Add", another window will appear with DefaultController. Change the name to HomeController and click "Add". The HomeController will be added under the Controllers folder. Don’t change the Controller suffix for all controllers, change only the highlight, and instead of Default, just change Home.
 
CURD Operation Using Repository Design Pattern In ASP.NET MVC
 
The complete code for HomeController.
  1. using MvcRepositoryDesignPattern_Demo.Models;  
  2. using MvcRepositoryDesignPattern_Demo.Repositories;  
  3. using System;  
  4. using System.Collections.Generic;  
  5. using System.Linq;  
  6. using System.Web;  
  7. using System.Web.Mvc;  
  8.    
  9. namespace MvcRepositoryDesignPattern_Demo.Controllers  
  10. {  
  11.     public class HomeController : Controller  
  12.     {  
  13.         private readonly IEmployeeRepository _employeeRepository;  
  14.    
  15.         public HomeController()  
  16.         {  
  17.             _employeeRepository = new EmployeeRepository(new EmployeeContext());  
  18.         }  
  19.    
  20.         public HomeController(IEmployeeRepository employeeRepository)  
  21.         {  
  22.             _employeeRepository = employeeRepository;  
  23.         }  
  24.    
  25.         public ActionResult Index()  
  26.         {  
  27.             var employee = _employeeRepository.GetEmployees();  
  28.             return View(employee);  
  29.         }  
  30.    
  31.         public ActionResult Details(int id)  
  32.         {  
  33.            var employee= _employeeRepository.GetEmployeeById(id);  
  34.             return View(employee);  
  35.         }  
  36.    
  37.         public ActionResult Create()  
  38.         {  
  39.             return View();  
  40.         }  
  41.    
  42.         [HttpPost]  
  43.         [ValidateAntiForgeryToken]  
  44.         public ActionResult Create(Employee employee)  
  45.         {  
  46.             if (ModelState.IsValid)  
  47.             {  
  48.                 _employeeRepository.NewEmployee(employee);  
  49.                 _employeeRepository.Save();  
  50.                 return RedirectToAction("Index");  
  51.             }  
  52.             return View();  
  53.         }  
  54.    
  55.         [HttpGet]  
  56.         public ActionResult Edit(int id)  
  57.         {  
  58.             var employee = _employeeRepository.GetEmployeeById(id);  
  59.             return View(employee);  
  60.         }  
  61.    
  62.         [HttpPost]  
  63.         public ActionResult Edit(Employee employee)  
  64.         {  
  65.             if (ModelState.IsValid)  
  66.             {  
  67.                 _employeeRepository.UpdateEmployee(employee);  
  68.                 _employeeRepository.Save();  
  69.                 return RedirectToAction("Index""Home");  
  70.    
  71.             }  
  72.             else  
  73.             {  
  74.                 return View(employee);  
  75.             }            
  76.         }  
  77.    
  78.         [HttpGet]  
  79.         public ActionResult Delete(int id)  
  80.         {  
  81.             var employee=_employeeRepository.GetEmployeeById(id);  
  82.             return View(employee);  
  83.         }  
  84.    
  85.         [HttpPost]  
  86.         public ActionResult ConfirmDelete(int id)  
  87.         {  
  88.             _employeeRepository.DeleteEmployee(id);  
  89.             _employeeRepository.Save();  
  90.             return RedirectToAction("Index","Home");  
  91.         }  
  92.     }  
  93. }  
Step 10
 
Right-click on the Index method in HomeController. The "Add View" window will appear with default index name checked (use a Layout page). Click on "Add.
 
CURD Operation Using Repository Design Pattern In ASP.NET MVC
 
Code for Index View -
  1. @model IEnumerable<MvcRepositoryDesignPattern_Demo.Models.Employee>  
  2. @{  
  3.     ViewBag.Title = "Index";  
  4. }  
  5.    
  6. <h3 class="text-center text-uppercase">List of Employee</h3>  
  7. <p>  
  8.     @Html.ActionLink("Create New""Create","",new {@class="btn btn-primary" })  
  9. </p>  
  10. <table class="table table-bordered">  
  11.     <thead>  
  12.         <tr>  
  13.             <th>@Html.DisplayNameFor(m => m.FirstName)</th>  
  14.             <th>@Html.DisplayNameFor(m => m.LastName)</th>  
  15.             <th>@Html.DisplayNameFor(m => m.Age)</th>  
  16.             <th>@Html.DisplayNameFor(m => m.Position)</th>  
  17.             <th>@Html.DisplayNameFor(m => m.Office)</th>  
  18.             <th>@Html.DisplayNameFor(m => m.Salary)</th>  
  19.             <th>Action(s)</th>  
  20.         </tr>  
  21.     </thead>  
  22.     <tbody>  
  23.         @foreach (var emp in Model)  
  24.         {  
  25.             <tr>  
  26.                 <td>@emp.FirstName</td>  
  27.                 <td>@emp.LastName</td>  
  28.                 <td>@emp.Age</td>  
  29.                 <td>@emp.Position</td>  
  30.                 <td>@emp.Office</td>  
  31.                 <td>@emp.Salary</td>  
  32.                 <td>  
  33.                    @Html.ActionLink("Details","Details",new {id=emp.Id },new {@class="btn btn-info"})  
  34.                    @Html.ActionLink("Edit""Edit"new { id = emp.Id }, new { @class = "btn btn-primary" })  
  35.                    @Html.ActionLink("Delete""Delete"new { id = emp.Id }, new { @class = "btn btn-danger" })  
  36.                 </td>  
  37.             </tr>  
  38.         }  
  39.     </tbody>  
  40. </table>  
CURD Operation Using Repository Design Pattern In ASP.NET MVC
 
Step 11
 
Right-click on the Details method in HomeController. The "Add View" window will appear with default details name checked (use a Layout page). Click on "Add.
 
Code for Details View -
  1. @model MvcRepositoryDesignPattern_Demo.Models.Employee  
  2. @{  
  3.     ViewBag.Title = "Details";  
  4. }  
  5.    
  6. <div class="card" style="width:60%; margin:auto;">  
  7.     <div class="card-header bg-dark text-white">  
  8.         <h5>Employee Details</h5>  
  9.     </div>  
  10.     <div class="card-body">  
  11.         <table class="table table-borderless">  
  12.             <tr>  
  13.                 <td>  
  14.                     <b>@Html.DisplayNameFor(m => m.FirstName)</b>  
  15.                 </td>  
  16.                 <td>@Html.DisplayFor(m => m.FirstName)</td>  
  17.                 <td>  
  18.                     <b>@Html.DisplayNameFor(m => m.LastName)</b>  
  19.                 </td>  
  20.                 <td>@Html.DisplayFor(m => m.LastName)</td>  
  21.             </tr>  
  22.             <tr>  
  23.                 <td>  
  24.                     <b>@Html.DisplayNameFor(m => m.Age)</b>  
  25.                 </td>  
  26.                 <td>@Html.DisplayFor(m => m.Age)</td>  
  27.                 <td>  
  28.                     <b>@Html.DisplayNameFor(m => m.Position)</b>  
  29.                 </td>  
  30.                 <td>@Html.DisplayFor(m => m.Position)</td>  
  31.             </tr>  
  32.             <tr>  
  33.                 <td>  
  34.                     <b>@Html.DisplayNameFor(m => m.Office)</b>  
  35.                 </td>  
  36.                 <td>@Html.DisplayFor(m => m.Office)</td>  
  37.                 <td>  
  38.                     <b>@Html.DisplayNameFor(m => m.Salary)</b>  
  39.                 </td>  
  40.                 <td>@Html.DisplayFor(m => m.Salary)</td>  
  41.             </tr>  
  42.         </table>  
  43.         <p>  
  44.             @Html.ActionLink("Edit""Edit"new { id = Model.Id },new {@class="btn btn-info"})  
  45.             @Html.ActionLink("Back to List""Index","",new {@class="btn btn-primary"})  
  46.         </p>  
  47.     </div>  
  48. </div>  
CURD Operation Using Repository Design Pattern In ASP.NET MVC
 
Step 12
 
Right-click the Create method in HomeController. The "Add View" window will appear with default Create name checked (use a Layout page). Click on "Add.
 
Code for Create View.
  1. @model MvcRepositoryDesignPattern_Demo.Models.Employee  
  2. @{  
  3.     ViewBag.Title = "Create";  
  4. }  
  5.    
  6. <div class="card" style="width:60%; margin:auto;">  
  7.     <div class="card-header bg-dark text-white">  
  8.         <h5>Create New</h5>  
  9.     </div>  
  10.     <div class="card-body">  
  11.         @using (Html.BeginForm())  
  12.         {  
  13.             @Html.AntiForgeryToken()  
  14.    
  15.             <div class="row">  
  16.                 <div class="col-md-6">  
  17.                     <div class="form-group">  
  18.                         @Html.LabelFor(m => m.FirstName)  
  19.                         @Html.TextBoxFor(m => m.FirstName, new { @class = "form-control" })  
  20.                         @Html.ValidationMessageFor(m => m.FirstName)  
  21.                     </div>  
  22.                 </div>  
  23.                 <div class="col-md-6">  
  24.                     <div class="form-group">  
  25.     @Html.LabelFor(m => m.LastName)  
  26.     @Html.TextBoxFor(m => m.LastName, new { @class = "form-control" })  
  27.     @Html.ValidationMessageFor(m => m.LastName)  
  28. </div>  
  29.                 </div>  
  30.             </div>  
  31.             <div class="row">  
  32.                 <div class="col-md-6">  
  33.                     <div class="form-group">  
  34.                         @Html.LabelFor(m => m.Age)  
  35.                         @Html.TextBoxFor(m => m.Age, new { @class = "form-control" })  
  36.                         @Html.ValidationMessageFor(m => m.Age)  
  37.                     </div>  
  38.                 </div>  
  39.                 <div class="col-md-6">  
  40.                     <div class="form-group">  
  41.                         @Html.LabelFor(m => m.Position)  
  42.                         @Html.TextBoxFor(m => m.Position, new { @class = "form-control" })  
  43.                         @Html.ValidationMessageFor(m => m.Position)  
  44.                     </div>  
  45.                 </div>  
  46.             </div>  
  47.             <div class="row">  
  48.                 <div class="col-md-6">  
  49.                     <div class="form-group">  
  50.                         @Html.LabelFor(m => m.Office)  
  51.                         @Html.TextBoxFor(m => m.Office, new { @class = "form-control" })  
  52.                         @Html.ValidationMessageFor(m => m.Office)  
  53.                     </div>  
  54.                 </div>  
  55.                 <div class="col-md-6">  
  56.                     <div class="form-group">  
  57.                         @Html.LabelFor(m => m.Salary)  
  58.                         @Html.TextBoxFor(m => m.Salary, new { @class = "form-control" })  
  59.                         @Html.ValidationMessageFor(m => m.Salary)  
  60.                     </div>  
  61.                 </div>  
  62.             </div>  
  63.             <div class="form-group">  
  64.                 <button type="submit" class="btn btn-primary">Submit</button>  
  65.             </div>  
  66.         }  
  67.     </div>  
  68. </div>  
CURD Operation Using Repository Design Pattern In ASP.NET MVC
 
Step 13
 
Right-click on the Edit method in HomeController. The "Add View" window will appear with the default "Edit" name checked (use a Layout page). Click on "Add.
 
Code for Edit View.
  1. @model MvcRepositoryDesignPattern_Demo.Models.Employee  
  2. @{  
  3.     ViewBag.Title = "Edit";  
  4. }  
  5.    
  6. <div class="card" style="width:60%; margin:auto;">  
  7.     <div class="card-header bg-dark text-white">  
  8.         <h3>Edit Employee</h3>  
  9.     </div>  
  10.     <div class="card-body">  
  11.         @using (Html.BeginForm())  
  12.         {  
  13.             @Html.AntiForgeryToken()  
  14.             @Html.HiddenFor(m => m.Id)  
  15.             <div class="row">  
  16.                 <div class="col-md-6">  
  17.                     <div class="form-group">  
  18.                         @Html.LabelFor(m => m.FirstName)  
  19.                         @Html.EditorFor(m => m.FirstName, new { htmlAttributes = new { @class = "form-control" } })  
  20.                         @Html.ValidationMessageFor(m => m.FirstName)  
  21.                     </div>  
  22.                 </div>  
  23.                 <div class="col-md-6">  
  24.                     <div class="form-group">  
  25.                         @Html.LabelFor(m => m.LastName)  
  26.                         @Html.EditorFor(m => m.LastName, new { htmlAttributes = new { @class = "form-control" } })  
  27.                         @Html.ValidationMessageFor(m => m.LastName)  
  28.                     </div>  
  29.                 </div>  
  30.             </div>  
  31.             <div class="row">  
  32.                 <div class="col-md-6">  
  33.                     <div class="form-group">  
  34.                         @Html.LabelFor(m => m.Age)  
  35.                         @Html.EditorFor(m => m.Age, new { htmlAttributes = new { @class = "form-control" } })  
  36.                         @Html.ValidationMessageFor(m => m.Age)  
  37.                     </div>  
  38.                 </div>  
  39.                 <div class="col-md-6">  
  40.                     <div class="form-group">  
  41.                         @Html.LabelFor(m => m.Position)  
  42.                         @Html.EditorFor(m => m.Position, new { htmlAttributes = new { @class = "form-control" } })  
  43.                         @Html.ValidationMessageFor(m => m.Position)  
  44.                     </div>  
  45.                 </div>  
  46.             </div>  
  47.             <div class="row">  
  48.                 <div class="col-md-6">  
  49.                     <div class="form-group">  
  50.                         @Html.LabelFor(m => m.Office)  
  51.                         @Html.EditorFor(m => m.Office, new { htmlAttributes = new { @class = "form-control" } })  
  52.                         @Html.ValidationMessageFor(m => m.Office)  
  53.                     </div>  
  54.                 </div>  
  55.                 <div class="col-md-6">  
  56.                     <div class="form-group">  
  57.                         @Html.LabelFor(m => m.Salary)  
  58.                         @Html.EditorFor(m => m.Salary, new { htmlAttributes = new { @class = "form-control" } })  
  59.                         @Html.ValidationMessageFor(m => m.Salary)  
  60.                     </div>  
  61.                 </div>  
  62.             </div>  
  63.             <div class="form-group">  
  64.                 <button type="submit" class="btn btn-primary">Update</button>  
  65.             </div>  
  66.         }  
  67.     </div>  
  68. </div>  
CURD Operation Using Repository Design Pattern In ASP.NET MVC
 
Step 14
 
Right-click on the Delete method in HomeController. The "Add View" window will appear with default Delete name checked (use a Layout page). Click on "Add.
 
Code for Delete View.
  1. @model MvcRepositoryDesignPattern_Demo.Models.Employee  
  2.    
  3. @{  
  4.     ViewBag.Title = "Delete";  
  5. }  
  6.    
  7. <h3 class="text-center text-uppercase">Delete Employee Record</h3>  
  8. <div class="card" style="width:50%; margin:auto;">  
  9.     <div class="card-header">  
  10.         <h3>Are you sure you want to delete this?</h3>  
  11.     </div>  
  12.     <div class="card-body">  
  13.         <div class="row">  
  14.             <div class="col-md-2">  
  15.    
  16.             </div>  
  17.             <div class="col-md-10">  
  18.             </div>  
  19.    
  20.         </div>  
  21.    
  22.         <dl class="dl-horizontal">  
  23.             <dt class="col-md-2">  
  24.                 @Html.DisplayNameFor(model => model.FirstName)  
  25.             </dt>  
  26.    
  27.             <dd class="col-md-10">  
  28.                 @Html.DisplayFor(model => model.FirstName)  
  29.             </dd>  
  30.    
  31.             <dt>  
  32.                 @Html.DisplayNameFor(model => model.LastName)  
  33.             </dt>  
  34.    
  35.             <dd>  
  36.                 @Html.DisplayFor(model => model.LastName)  
  37.             </dd>  
  38.    
  39.             <dt>  
  40.                 @Html.DisplayNameFor(model => model.Age)  
  41.             </dt>  
  42.    
  43.             <dd>  
  44.                 @Html.DisplayFor(model => model.Age)  
  45.             </dd>  
  46.    
  47.             <dt>  
  48.                 @Html.DisplayNameFor(model => model.Position)  
  49.             </dt>  
  50.    
  51.             <dd>  
  52.                 @Html.DisplayFor(model => model.Position)  
  53.             </dd>  
  54.    
  55.             <dt>  
  56.                 @Html.DisplayNameFor(model => model.Office)  
  57.             </dt>  
  58.    
  59.             <dd>  
  60.                 @Html.DisplayFor(model => model.Office)  
  61.             </dd>  
  62.    
  63.             <dt>  
  64.                 @Html.DisplayNameFor(model => model.Salary)  
  65.             </dt>  
  66.    
  67.             <dd>  
  68.                 @Html.DisplayFor(model => model.Salary)  
  69.             </dd>  
  70.    
  71.             <dt>  
  72.                 @Html.DisplayNameFor(model => model.Salary)  
  73.             </dt>  
  74.    
  75.             <dd>  
  76.                 @Html.DisplayFor(model => model.Salary)  
  77.             </dd>  
  78.         </dl>  
  79.         @using (Html.BeginForm())  
  80.         {  
  81.             @Html.AntiForgeryToken()  
  82.             <div class="form-actions no-color">  
  83.                 <input type="submit" value="Delete" class="btn btn-danger" /> |  
  84.                 @Html.ActionLink("Back to List""Index")  
  85.             </div>  
  86.         }  
  87.     </div>  
  88. </div>  
CURD Operation Using Repository Design Pattern In ASP.NET MVC


Similar Articles