This article shows how to Retrieve all 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); }
Step-3: Add View "Profile". And write these below coding in the 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> </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> </tr> } </table> </div>
0 Comments