CRUD (Create, Read, Update, Delete) in asp.net MVC 5 using jquery
steps from creating application
CRUD_OP.cshtml should look like this
To Add employeeOp.js: right click on scripts folder->Add->Javascript file name it employeeOp.js add the following code to it.
Now run the application navigate to localhost: /Employee/CRUD_OP it will be fully functional.
jquery and bootstrap is included by default in MVC5. We can easily develop ajax application easily in MVC5 using jquery. Json can easily be return from action method by setting return type to JsonResult and by marking that method with [HttpPost]
[HttpPost]
public JsonResult AddEmployee(Employee emp)
{
return Json(true, JsonRequestBehavior.AllowGet);
}
public JsonResult AddEmployee(Employee emp)
{
return Json(true, JsonRequestBehavior.AllowGet);
}
In this Article. I will show you how can we develop a single page application. with CRUD operations using (Microsoft Entity Framework 6.0) in Visual Studio 2013
Run the following script to create tables(Employee,Position) in sql server 2008 (SSMS) 1 | USE [HRDB] |
- Create the database in Sql Server 2008 i used the database named(HRDB)
- Create new MVC project in visual studio 2013
- Right Click on Models folder select Add->New Item->Visual C#->Data->ADO.NET Entity Data Model->EF Designer from Database
- Name it (HRDBModel)
- Add Empty Controller (EmployeeController)
1 | using System; |
Right Click on CRUD_OP() action method and select Add View with options shown in screenshot
CRUD_OP.cshtml should look like this
1 | @model IEnumerable<MyApp.Models.Employee> |
1 | $(function () { |
Now run the application navigate to localhost: /Employee/CRUD_OP it will be fully functional.
1 Comments
Thank you sir ji, but we can also achieve the same with builtin ASP.NET AJAX.BEGINFORM(), if someone is not coming from JavaScript/jQuery background then it will be easy to use that built in functionality of ASP.NET MVC.
ReplyDeletePost a Comment