Create custom data access object in ASP.NET MVC 5 application

Posted By: Ajay Saptaputre, 11 Aug,2015 Total View : 1871
submit to reddit

In this article I am going to discuss how to create custom data access object for ASP.NET MVC 5 application to perform CRUD operation like create, retrieve, update and delete the data into the database without using Entity Framework.

In my previous articles, I have been using Entity Framework and entities. Where entities are mapped to the database tables and ORM tools like Entity Framework and NHibernet are used to automatically generate data access model class to retrieve and save the data into the database.

In this article I am going to discuss how to create custom data access object using class library to access database and also show how to use them as data access model in our sample ASP.NET MVC 5 application. You can access database with any other ORM like NHibernate, Entity Framework or you can create your custom data access library as we are doing here. ASP.NET MVC 5 also supports to use custom data access library.

Before creating ASP.NET MVC 5 application let's first create database table with columns and insert some data. This table would be used to save the employee information.

CREATE TABLE [tblEmployee](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[FullName] [varchar](50) NULL,
	[Designation] [varchar](100) NULL,
	[Gender] [varchar](10) NULL,
	[JoinDate] [date] NULL,
	[Salary] [float] NULL,
	[City] [varchar](50) NULL,
	[State] [varchar](50) NULL,
	[Zip] [int] NULL
 CONSTRAINT [PK_tblEmployee] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, 
ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

Now insert some records into the "Employee" table.

INSERT [tblEmployee]([Name],[Designation],[Gender],[Role],[Salary],[City],[State],[Zip]) 
VALUES (N'Devendra S',N'Project Lead',N'Male','Manager',12000,N'Bhopal',N'MP',21323)
INSERT [dbo].[tblEmployee]([Name],[Designation],[Gender],[Role],[Salary],[City],[State],[Zip]) 
VALUES (N'Ram M',N'Engineer IT',N'Male','Developer',8000,N'Indore',N'MP',23333)
INSERT [dbo].[tblEmployee]([Name],[Designation],[Gender],[Role],[Salary],[City],[State],[Zip]) 
VALUES (N'Manish S',N'Manager',N'Male','QA',9000,N'Delhi',N'Delhi',32334)
INSERT [dbo].[tblEmployee]([Name],[Designation],[Gender],[Role],[Salary],[City],[State],[Zip]) 
VALUES (N'Rahul E',N'Software Engineer',N'Male','Tech Lead',12000,N'Indore',N'AP',45654)

In order to perform CRUD operation the database table "tblEmployee" we need stored procedures to perform data retrieve, update, delete and insert operations so let's create stored procedures here. To do so easy.

GO
CREATE PROCEDURE [dbo].[uspGetEmployee]
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	SELECT * from tblEmployee
	
END

GO
CREATE PROCEDURE [dbo].[uspDeleteEmployee]
(@id INT) 
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
    DELETE FROM tblEmployee WHERE id = @id
END

GO
CREATE PROCEDURE [dbo].[uspEditEmployee]
(@id INT,
@fullName varchar(50),
@designation varchar(50),
@gender varchar(10),
@city varchar(50),
@role varchar(25),
@state varchar(50),
@zip int,
@phone varchar(12)
) 
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
    UPDATE tblEmployee SET Name = @name, Designation = @designation,
	Gender = @gender,Role = @role, City = @city,State =@state,
    Zip = @zip, Phone = @phone  WHERE id = @id
END

GO
CREATE PROCEDURE [dbo].[uspInsertEmployee]
(@name varchar(50),
@designation varchar(50),
@gender varchar(10),
@city varchar(50),
@role varchar(25),
@state varchar(50),
@salary float,
@zip int,
@phone varchar(12)
) 
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
    INSERT INTO tblEmployee(Name,Designation,Gender,City,Role,State,Salary,Zip,Phone)  
    VALUES (@name,@designation,@gender,@city,@Role,@state,@salary,@zip,@phone)
END

All right, database table and stored procedures are ready for action. Now start creating ASP.NET MVC 5 project in VS 2013.

Step 1: Start Visual studio 2013, click on "New" Project from "File" menu and select "Web" and then "ASP.NET web application" from "New Project". I am selecting .Net framework 4.5 to build this sample application. Now give proper name to the application, I am saying "MVCCustomObject" now click "Ok" button as below screen shot illustrate:

Step 2: Once done, you will see another window which asked to select "Template". Select "Empty" and click on "Ok" button as bellow screen shot illustrate:

Step 3: Because we are not creating any Model in our application, we can remove "Models" folder from solution it is not require at all. The Models can reside anywhere, it could be reside in a separate assembly and use as Model. Now right click on solution and select "Add" and then "New Project". .

Step 4: Now, select "Visual C#" and then select "Class Library". Give proper name to library and click "Ok" button. This will add new project in our solution. Rename new class as "DataAccessLayer" and save the project.

Step 5: Add below code to the "DataAccessLayer" class.

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Configuration;
using DataAccessLayer;

namespace DataAccessLayer
{
    public class DataAccessLib
    {
	public List GetEmployees
	{
		get
		{
		string con = ConfigurationManager.ConnectionStrings["connectionStr"].ToString();
		SqlConnection sql_conn = new SqlConnection(con);
		sql_conn.Open();
		List empList = new List();
		Employee emp;
		SqlDataReader reader = null;
		DataTable dt_scheduled_appts = new DataTable();
		using (SqlCommand sql_command = new SqlCommand("uspGetEmployee", sql_conn))
		{
			sql_command.CommandType = CommandType.StoredProcedure;
			sql_command.Parameters.Clear();
			reader = sql_command.ExecuteReader();

			while (reader.Read())
			{
				emp = new Employee();
				emp.Id = Convert.ToInt32(reader["id"]);
				emp.Name = reader["Name"].ToString();
				emp.Designation = reader["Designation"].ToString();
				emp.Gender = reader["Gender"].ToString();
				emp.Role = reader["Role"].ToString();
				emp.Salary = Convert.ToDouble(reader["Salary"]);
				emp.City = reader["City"].ToString();
				emp.State = reader["State"].ToString();
				emp.Zip = reader["Zip"].ToString();
				emp.Address = reader["Address"].ToString();
				empList.Add(emp);
			}
			return empList;
		}
	}
   }
	public void AddEmployees(Employee emp)
	{
		string con = ConfigurationManager.ConnectionStrings["connectionStr"].ToString();
		SqlConnection sql_conn = new SqlConnection(con);
		sql_conn.Open();
		using (SqlCommand sql_command = new SqlCommand("uspInsertEmployee", sql_conn))
		{
			sql_command.CommandType = CommandType.StoredProcedure;
			sql_command.Parameters.Clear();
			sql_command.Parameters.AddWithValue("@name", emp.Name);
			sql_command.Parameters.AddWithValue("@designation", emp.Designation);
			sql_command.Parameters.AddWithValue("@gender", emp.Gender);
			sql_command.Parameters.AddWithValue("@role", emp.Role);
			sql_command.Parameters.AddWithValue("@salary", emp.Salary);
			sql_command.Parameters.AddWithValue("@city", emp.City);
			sql_command.Parameters.AddWithValue("@state", emp.State);
			sql_command.Parameters.AddWithValue("@zip", emp.Zip);
			sql_command.Parameters.AddWithValue("@address", emp.Address);
			sql_command.ExecuteNonQuery();
		}
	}
	public void DeleteEmployees(int id)
	{
		string con = ConfigurationManager.ConnectionStrings["connectionStr"].ToString();
		SqlConnection sql_conn = new SqlConnection(con);
		sql_conn.Open();
		DataTable dt_scheduled_appts = new DataTable();
		using (SqlCommand sql_command = new SqlCommand("uspDeleteEmployee", sql_conn))
		{
			sql_command.CommandType = CommandType.StoredProcedure;
			sql_command.Parameters.Clear();
			sql_command.Parameters.AddWithValue("@id", id);
			sql_command.ExecuteNonQuery();
		}
	}
	public void UpdateEmployees(Employee emp)
	{
		string con = ConfigurationManager.ConnectionStrings["connectionStr"].ToString();
		SqlConnection sql_conn = new SqlConnection(con);
		sql_conn.Open();
		using (SqlCommand sql_command = new SqlCommand("uspEditEmployee", sql_conn))
		{
			sql_command.CommandType = CommandType.StoredProcedure;
			sql_command.Parameters.Clear();
			sql_command.Parameters.AddWithValue("@name", emp.Name);
			sql_command.Parameters.AddWithValue("@designation", emp.Designation);
			sql_command.Parameters.AddWithValue("@gender", emp.Gender);
			sql_command.Parameters.AddWithValue("@role", emp.Role);
			sql_command.Parameters.AddWithValue("@salary", emp.Salary);
			sql_command.Parameters.AddWithValue("@city", emp.City);
			sql_command.Parameters.AddWithValue("@state", emp.State);
			sql_command.Parameters.AddWithValue("@zip", emp.Zip);
			sql_command.Parameters.AddWithValue("@address", emp.Address);
			sql_command.ExecuteNonQuery();
		}
	}
    }
}

Step 6: We will need a class that will used to map our database table called "Employee", so let's add another class into the class library project and name it as "Employee". All right, now add properties to the class as below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataAccessLayer
{
    public class Employee
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Designation { get; set; }
        public string Role { get; set; }
        public string Gender { get; set; }
        public double Salary { get; set; }
        public string City { get; set; }
        public string State { get; set; }
        public string Zip { get; set; }
        public string Address { get; set; }
    }
}

Step 7: Now right click on project and build the application. Open web.config file and add connection string to connect to the database as below screen shot:

Step 8: Build the data access library and set reference to ASP.NET MVC project that we have created.

Step 9: Now go to our ASP.NET MVC project and right click on "Controllers" folder and select empty from options give controller name as "EmployeeController" and click "Add" button.

Step 10: Add below code to the Employee controller class. You can see here controller methods decorated with "ActionName". The "ActionName" attribute used to expose action methods with user friendly name to the outside world.

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DataAccessLayer;

namespace MVCCustomObject.Controllers
{
    public class EmployeeController : Controller
    {
        public ActionResult Index()
        {
            DataAccessLib db = new DataAccessLib();
            List employee = db.GetEmployees;
            return View(employee);
        }

        public ActionResult Details(int id = 0)
        {
            DataAccessLib db = new DataAccessLib();
            List employee = db.GetEmployees;
            Employee emp = employee.Single(m => m.Id == id);
            if (emp == null)
            {
                return HttpNotFound();
            }
            return View(emp);
        }
        [ActionName("Insert")]
        [HttpGet]
        public ActionResult Index_insert()
        {
            return View();
        }

        [ActionName("Insert")]
        [HttpPost]
        public ActionResult Index_insert(Employee emp)
        {
            DataAccessLib db = new DataAccessLib();
            db.AddEmployees(emp);

            return RedirectToAction("Index");
        }

        [ActionName("Delete")]
        [HttpGet]
        public ActionResult Delete(int id = 0)
        {
            DataAccessLib db = new DataAccessLib();
            List employee = db.GetEmployees;
            Employee emp = employee.Single(m => m.Id == id);
            if (emp == null)
            {
                return HttpNotFound();
            }
            return View(emp);
        }

        [ActionName("Delete")]
        [HttpPost]
        public ActionResult Index_delete(Employee emp)
        {
            DataAccessLib db = new DataAccessLib();
            db.DeleteEmployees(emp.Id);

            return RedirectToAction("Index");
        }

        [ActionName("Update")]
        [HttpGet]
        public ActionResult Index_update(int id = 0)
        {
            DataAccessLib db = new DataAccessLib();
            List employee = db.GetEmployees;
            Employee emp = employee.Single(m => m.Id == id);
            if (emp == null)
            {
                return HttpNotFound();
            }
            return View(emp);
        }

        [ActionName("Update")]
        [HttpPost]
        public ActionResult Index_update(Employee emp)
        {
            DataAccessLib db = new DataAccessLib();
            db.UpdateEmployees(emp);

            return RedirectToAction("Index");
        }
    }
}

Step 11: Now, right click on "Index" method from controller and select "Add View" from popup menu. Select "Template" as empty and click "Add" button. Add below code to the "Index" view.

@model IEnumerable<DataAccessLayer.Employee>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Insert")
</p>
<table border="1">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Designation)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Role)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Gender)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Salary)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.City)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.State)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Zip)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Address)
        </th>
        <th>Operations</th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Designation)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Role)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Gender)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Salary)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.City)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.State)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Zip)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Address)
            </td>
            <td>
                @Html.ActionLink("Edit", "Update", new { id = item.Id }) |
                @Html.ActionLink("Details", "Details", new { id = item.Id }) |
                @Html.ActionLink("Delete", "Delete", new { id = item.Id })
            </td>
        </tr>
    }

</table>

Step 12: Now, right click on "Delete" method from controller and select "Add View" from popup menu. Select "Template" as empty and click "Add" button. Add below code to the "Delete" view.

@model DataAccessLayer.Employee

@{
    ViewBag.Title = "Delete";
}

<h2>Delete</h2>

<h3>Are you sure you want to delete this?</h3>
<fieldset>
    <legend>Employee</legend>

    <div class="display-label">
        @Html.DisplayNameFor(model => model.Name)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Name)
    </div>

    <div class="display-label">
        @Html.DisplayNameFor(model => model.Designation)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Designation)
    </div>

    <div class="display-label">
        @Html.DisplayNameFor(model => model.Role)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Role)
    </div>

    <div class="display-label">
        @Html.DisplayNameFor(model => model.Gender)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Gender)
    </div>

    <div class="display-label">
        @Html.DisplayNameFor(model => model.Salary)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Salary)
    </div>

    <div class="display-label">
        @Html.DisplayNameFor(model => model.City)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.City)
    </div>

    <div class="display-label">
        @Html.DisplayNameFor(model => model.State)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.State)
    </div>

    <div class="display-label">
        @Html.DisplayNameFor(model => model.Zip)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Zip)
    </div>

    <div class="display-label">
        @Html.DisplayNameFor(model => model.Address)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Address)
    </div>
</fieldset>
@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    <p>
        <input type="submit" value="Delete" /> |
        @Html.ActionLink("Back to List", "Index")
    </p>
}
Step 13: Now, right click on "Details" method from controller and select "Add View" from popup menu. Select "Template" as empty and click "Add" button. Add below code to the "Details" view.

@model DataAccessLayer.Employee

@{
    ViewBag.Title = "Details";
}

<h2>Details</h2>

<fieldset>
    <legend>Employee</legend>

    <div class="display-label">
        @Html.DisplayNameFor(model => model.Name)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Name)
    </div>

    <div class="display-label">
        @Html.DisplayNameFor(model => model.Designation)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Designation)
    </div>

    <div class="display-label">
        @Html.DisplayNameFor(model => model.Role)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Role)
    </div>

    <div class="display-label">
        @Html.DisplayNameFor(model => model.Gender)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Gender)
    </div>

    <div class="display-label">
        @Html.DisplayNameFor(model => model.Salary)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Salary)
    </div>

    <div class="display-label">
        @Html.DisplayNameFor(model => model.City)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.City)
    </div>

    <div class="display-label">
        @Html.DisplayNameFor(model => model.State)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.State)
    </div>

    <div class="display-label">
        @Html.DisplayNameFor(model => model.Zip)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Zip)
    </div>

    <div class="display-label">
        @Html.DisplayNameFor(model => model.Address)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Address)
    </div>
</fieldset>
<p>
    @Html.ActionLink("Edit", "Update", new { id = Model.Id }) |
    @Html.ActionLink("Back to List", "Index")
</p>
Step 14: Now, right click on "Insert" method from controller and select "Add View" from popup menu. Select "Template" as empty and click "Add" button. Add below code to the "Insert" view.

@model DataAccessLayer.Employee

@{
    ViewBag.Title = "Create";
}

<h2>Create</h2>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Employee</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.Name)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Name)
            @Html.ValidationMessageFor(model => model.Name)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Designation)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Designation)
            @Html.ValidationMessageFor(model => model.Designation)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Role)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Role)
            @Html.ValidationMessageFor(model => model.Role)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Gender)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Gender)
            @Html.ValidationMessageFor(model => model.Gender)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Salary)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Salary)
            @Html.ValidationMessageFor(model => model.Salary)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.City)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.City)
            @Html.ValidationMessageFor(model => model.City)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.State)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.State)
            @Html.ValidationMessageFor(model => model.State)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Zip)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Zip)
            @Html.ValidationMessageFor(model => model.Zip)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Address)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Address)
            @Html.ValidationMessageFor(model => model.Address)
        </div>

        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
Step 15: Now, right click on "Update" method from controller and select "Add View" from popup menu. Select "Template" as empty and click "Add" button. Add below code to the "Update" view.

@model DataAccessLayer.Employee

@{
    ViewBag.Title = "Edit";
}

<h2>Edit</h2>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Employee</legend>

        @Html.HiddenFor(model => model.Id)

        <div class="editor-label">
            @Html.LabelFor(model => model.Name)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Name)
            @Html.ValidationMessageFor(model => model.Name)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Designation)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Designation)
            @Html.ValidationMessageFor(model => model.Designation)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Role)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Role)
            @Html.ValidationMessageFor(model => model.Role)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Gender)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Gender)
            @Html.ValidationMessageFor(model => model.Gender)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Salary)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Salary)
            @Html.ValidationMessageFor(model => model.Salary)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.City)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.City)
            @Html.ValidationMessageFor(model => model.City)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.State)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.State)
            @Html.ValidationMessageFor(model => model.State)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Zip)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Zip)
            @Html.ValidationMessageFor(model => model.Zip)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Address)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Address)
            @Html.ValidationMessageFor(model => model.Address)
        </div>

        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
Step 16: All right, now run the application. This will display all the employees from "Employee" table with Insert, Update, Delete and Details operations. You can perform any operation like Entity Framework with Scaffold template.

Download Code ⇩

Appreciate your valuable feedback:

I hope this article is useful for you. I look forward for your comments and feedback. So please provide your valuable feedback so that I can make this blog better. You can also share this article by hitting below button.
Happy learning...

 
 
SHARE THIS IF YOU LIKE!
submit to reddit
SUBSCRIBE FOR LATEST UPDATES
HAVE WE CONNECTED ON FACEBOOK?
TOP TUTORIALSTOP CODE EXAMPLESTOP LIVE DEMOLINKSSTAY CONNECTED
HTML Tutorial
HTML5 Tutorial
Bootstrap3 Tutorial
Javascript Tutorial
TypeScript Tutorial
AngularJS Tutorial
CSharp Tutorial
PHP Tutorial
Developer Tools
Javascript
AngularJS
Google MAP API V3
ASP.NET
Javascript
AngularJS
Google MAP API V3
Contact Us
Advertise with Us
Privacy Policy
Disclaimer
Stay connected. We actually like you. If you want to get up to the minute updates, then connect with us on your fav below.
 
Twitter   Linkedin   Facebook   Google+    RSS   Pinterest
 
Protected by Copyscape Original Content Checker
 
 
Copyright ©2017 www.techstrikers.com Unauthorized reproduction/replication of any part of this site is prohibited.