Retrieve all Records in ASP.NET MVC Application using Entity FrameWork

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>

Step-4: Output

asp.net, asp net,sql server,mvc, asp net mvc,crud operation in asp.net mvc ,crud operation in c#, retrieve data in sql server in asp.net mvc,retrieve data in sql server in mvc,how to retrieve data in sql server in asp.net mvc,how to retrieve 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

0 Comments