Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jay PankhaniyaRank #798 · 2.9K reputationPosted Aug 8, 2023, 7:19 AM EDT
https://www.c-sharpcorner.com/article/crud-operation-in-asp-net-mvc2/
Please refer to the attached article
Tahir AnsariRank #366 · 6.8K reputationPosted Aug 8, 2023, 8:05 AM EDT
try below article using asp.net mvc5:
https://www.c-sharpcorner.com/UploadFile/0c1bb2/insertupdatedelete-in-Asp-Net-mvc-5-using-ado-net/
Vishal YelveRank #178 · 13.6K reputationPosted Aug 10, 2023, 6:54 AM EDT
Hi,
Do refer below articles
https://www.aspsnippets.com/Articles/MVC-ADONet-CRUD-Select-Insert-Edit-Update-and-Delete-using-ADONet-in-ASPNet-MVC-Razor.aspx
https://www.compilemode.com/2016/05/video-crud-operation-in-Asp-Net-mvc-using-entity-framework.html?m=1
https://www.c-sharpcorner.com/UploadFile/0c1bb2/insertupdatedelete-in-Asp-Net-mvc-5-using-ado-net/
Rijwan AnsariRank #82 · 24.2K reputationPosted Aug 10, 2023, 9:16 AM EDT
https://www.c-sharpcorner.com/article/crud-operation-in-asp-net-mvc2/
Abhishek YadavRank #217 · 11.3K reputationPosted Aug 17, 2023, 4:58 AM EDT
o perform CURD (Create, Update, Read, Delete) operations in ASP.NET MVC, follow these steps:
Create a new ASP.NET MVC project in Visual Studio.
Define the model for your data. This can be done by creating a new folder called "Models" in the project and adding a new class for your model. For example, if you are creating a simple employee management system, you can create a class called "Employee" with properties like Id, Name, Age, etc.
Create a new folder called "Controllers" in the project and add a new controller class. For example, you can create a class called "EmployeeController".
In the controller class, define the actions for each CURD operation. For example, you can have methods like "Create", "Edit", "Details", "Delete", etc. In these methods, you can perform the necessary logic to interact with the database or other data sources.
Create the corresponding views for each action. Views are used to display the data and receive user input. For example, you can have views like "Create.cshtml", "Edit.cshtml", "Details.cshtml", "Delete.cshtml", etc. You can use HTML helpers or Razor syntax to generate the necessary HTML elements for CRUD operations.
In the views, you can use form elements, buttons, and other HTML components to handle user input. You can also display the data from the model using Razor syntax.
In the controller actions, you can use the built-in model binding feature to automatically populate the model properties with user input. You can then perform the necessary CRUD operations using a database or other data sources.
To handle form submission and other user interactions, you can use HTTP verbs like GET and POST. For example, you can use the [HttpGet] and [HttpPost] attributes on your controller actions to specify the HTTP verb to be used.
Additionally, you can use validation attributes on the model properties to enforce data validation rules. For example, you can add [Required], [Range], or [RegularExpression] attributes to ensure that the user enters valid data.
Finally, you can deploy and run your ASP.NET MVC application to test and use the CRUD operations.
That's it! By following these steps, you can perform CURD operations in ASP.NET MVC. Remember to handle exceptions, secure your application, and follow best practices for database access and data validation.
Amit MohantyRank #112 · 20K reputationPosted Aug 10, 2023, 7:15 AM EDT
Please refer to the below articles:
https://www.tutlane.com/tutorial/aspnet-mvc/ado-net-crud-operations-insert-update-delete-in-asp-net-mvc-4-example
https://ankitsharmablogs.com/crud-operation-with-asp-net-core-mvc-using-ado-net/
https://www.dotnettricks.com/learn/knockout/knockout-crud-operations-using-mvc4
Saravanan GanesanRank #153 · 15.1K reputationPosted Aug 14, 2023, 9:12 AM EDT
In ASP.NET MVC, CRUD (Create, Read, Update, Delete) operations can be achieved by following these steps:
Keep in mind MVC principles: Models represent data, Views display content, and Controllers handle requests. Use appropriate HTTP methods for each operation (GET for Read, POST for Create/Update/Delete).
Cr BhargaviRank #420 · 5.9K reputationPosted Aug 14, 2023, 9:47 AM EDT
public class EmployeeController : Controller { private ApplicationDbContext db = new ApplicationDbContext(); // Read (Retrieve) public ActionResult Index() { var employees = db.Employees.ToList(); return View(employees); } // Create (Insert) public ActionResult Create() { return View(); } [HttpPost] public ActionResult Create(Employee employee) { if (ModelState.IsValid) { db.Employees.Add(employee); db.SaveChanges(); return RedirectToAction("Index"); } return View(employee); } // Update (Edit) public ActionResult Edit(int id) { var employee = db.Employees.Find(id); if (employee == null) { return HttpNotFound(); } return View(employee); } [HttpPost] public ActionResult Edit(Employee employee) { if (ModelState.IsValid) { db.Entry(employee).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(employee); } // Delete public ActionResult Delete(int id) { var employee = db.Employees.Find(id); if (employee == null) { return HttpNotFound(); } return View(employee); } [HttpPost, ActionName("Delete")] public ActionResult DeleteConfirmed(int id) { var employee = db.Employees.Find(id); db.Employees.Remove(employee); db.SaveChanges(); return RedirectToAction("Index"); } }