How to perform crud operations in asp.net?
How to perform crud operations in asp.net?
How to perform crud operations in asp.net?
Ans: Backend code to perform crud:
Start after name space.
namespace PracticeCrud.Controllers
{
public class HomeController : Controller
{
private readonly DatabaseName db = new DatabaseName ();
//
// GET: /Home/
public ActionResult Index()
{
var List = db.DatabaseTableName.ToList or Get();
return View(List);
}
//Get.data//
public ActionResult Create()
{
return View();
}
//post.data//
[HttpPost]
public ActionResult Create(DatabaseTableName model )
{
db.DatabaseTableName.Add(model);
db.SaveChanges();
return RedirectToAction("Create");
}
//Edit.Get//..
public ActionResult Edit(int id)
{
var Edt = db.DatabaseTableName.FirstOrDefault(w => w.Id == id);
return View(Edt);
}
//Edit.post//
[HttpPost]
public ActionResult Edit(DatabaseTableName model)
{
if (ModelState.IsValid)
{
db.Entry(model).State = EntityState.Modified;
db.SaveChanges();
}
return RedirectToAction("Index");
}
//Detail.Get//
public ActionResult Details(int id=0)
{
var Detal = db.DatabaseTableName.FirstOrDefault
(w => w.Id ==id);
return View(Detal);
}
//Delete//
public ActionResult Delete(int? id)
{
var delt = db.DatabaseTableName.FirstOrDefault
(w => w.Id == id);
db.OsTBs.Remove(delt);
db.SaveChanges();
return RedirectToAction("Index");
}
}
}
How to perform crud operations in asp.net?
Ans: Backend code to perform crud:
Start after name space.
namespace PracticeCrud.Controllers
{
public class HomeController : Controller
{
private readonly DatabaseName db = new DatabaseName ();
//
// GET: /Home/
public ActionResult Index()
{
var List = db.DatabaseTableName.ToList or Get();
return View(List);
}
//Get.data//
public ActionResult Create()
{
return View();
}
//post.data//
[HttpPost]
public ActionResult Create(DatabaseTableName model )
{
db.DatabaseTableName.Add(model);
db.SaveChanges();
return RedirectToAction("Create");
}
//Edit.Get//..
public ActionResult Edit(int id)
{
var Edt = db.DatabaseTableName.FirstOrDefault(w => w.Id == id);
return View(Edt);
}
//Edit.post//
[HttpPost]
public ActionResult Edit(DatabaseTableName model)
{
if (ModelState.IsValid)
{
db.Entry(model).State = EntityState.Modified;
db.SaveChanges();
}
return RedirectToAction("Index");
}
//Detail.Get//
public ActionResult Details(int id=0)
{
var Detal = db.DatabaseTableName.FirstOrDefault
(w => w.Id ==id);
return View(Detal);
}
//Delete//
public ActionResult Delete(int? id)
{
var delt = db.DatabaseTableName.FirstOrDefault
(w => w.Id == id);
db.OsTBs.Remove(delt);
db.SaveChanges();
return RedirectToAction("Index");
}
}
}
Share This with your friend by choosing any social account
You may also read following recent articles
![]() |
Is Chat GPT Use Of Web Content Fair!
Junaid A 29-Jan-2023 |
![]() |
Office politics examples!
Junaid A 28-Jan-2023 |
![]() |
ten jokes about the status of ChatGPT!
Junaid A 17-Jan-2023 |
![]() |
Image Resizing On Uploadig!
shahid Riaz 02-Jan-2019 |
![]() |
Hosting Server Connect Timeout!
Junaid A 13-Apr-2018 |
![]() |
What I can do after BS!
12-Apr-2018 |
|
Best hosting for windows!
05-Apr-2018 |
![]() |
Why cv is rejected!
30-Mar-2018 |
|
How to Integrated The Theme in Project!
shaheer 27-Mar-2018 |
![]() |
How to perform crud operations in asp.net?!
27-Mar-2018 |
![]() |
How to perform crud operations in asp.net?!
27-Mar-2018 |
![]() |
What is outer join in database?!
Arsal Ahmed 20-Mar-2018 |
![]() |
What is right join in database?!
Arsal Ahmed 20-Mar-2018 |