Delete Records in ASP.NET MVC Application using Entity FrameWork

This article shows how to Delete Records in ASP.NET MVC Application using Entity Framework. Follow These below steps:

Step-1: Create Table

CREATE TABLE [dbo].[tbl_registration] (
    [Loginid]  INT           IDENTITY (1, 1) NOT NULL,
    [FullName] VARCHAR (MAX) NULL,
    [UserName] VARCHAR (MAX) NULL,
    [Password] VARCHAR (MAX) NULL,
    [Email]    VARCHAR (MAX) NULL,
    [Age]      INT           NULL,
    [Gender]   VARCHAR (50)  NULL,
    [Religion] VARCHAR (50)  NULL,
    [Image]    VARCHAR (MAX) NULL,
    PRIMARY KEY CLUSTERED ([Loginid] ASC)
);

Step-2: Write below coding in Controller

public ActionResult Contact()
        {
            var aa = ob.tbl_registration.ToList();
            return View(aa);
        }
public ActionResult Delete(int Loginid)
        {
            tbl_registration on = ob.tbl_registration.Find(Loginid);
            ob.tbl_registration.Remove(on);
            ob.SaveChanges();
            return RedirectToAction("Contact");
        }

Step-3: Add View "Profile". And write these below coding in view page

@model List<Demo_mvc_application.Models.tbl_registration>
@{
    ViewBag.Title = "Contact";
    Layout = "~/Views/Shared/_Master.cshtml";
}
<h2>Contact</h2> <div class="col-md-12">
<h1>Student</h1>
    <table style="width:100%">         <tr>             <th style="width:10%">FullName</th>             <th style="width:10%">UserName</th>             <th style="width:10%">Email</th>             <th style="width:10%">Gender</th>             <th style="width:10%"> Age</th>             <th style="width:10%">Religion</th>             <th style="width:10%">Delete</th>         </tr>         @foreach (var student in Model)         {             <tr>                 <td>@student.FullName</td>                 <td>@student.UserName</td>                 <td>@student.Email</td>                 <td>@student.Gender</td>                 <td>@student.Age</td>                 <td>@student.Religion</td>                 <td>@Html.ActionLink("Delete", "Delete", new { Loginid = student.Loginid})</td>             </tr>         }     </table> </div>

Step-4: Output

asp.net, asp net,sql server,mvc, asp net mvc,crud operation in asp.net mvc ,crud operation in c#, remove data in sql server in asp.net mvc,remove data in sql server in mvc,how to remove data in sql server in asp.net mvc,how to remove data in sql server in mvc,Simple CRUD Operation In mvc, CRUD Operations mvc and C# in ASP.Net,CRUD with mvc,What is Create, Retrieve, Update and Delete (CRUD) using Entity Framework and C# in ASP.Net mvc,Retrieve, Insert, Update & Delete Using Entity Framework in mvc, how to Retrieve, Insert, Update & Delete Using Entity Framework in asp.net,Entity Framework , CRUD with Entity Framework  and c# , CRUD using Entity Framework and mvc

Post a Comment

1 Comments

  1. हिंदू नववर्षाच्या आणि गुढीपाडव्याच्या हार्दिक शुभेच्छा..!!!

    ReplyDelete