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>
1 Comments
हिंदू नववर्षाच्या आणि गुढीपाडव्याच्या हार्दिक शुà¤ेच्छा..!!!
ReplyDelete