Retrieve one Record in ASP.NET MVC Application using Entity FrameWork

This article shows how to Retrieve one Record from Database 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 Profile()
        {
            var v = (from a in ob.tbl_registration.ToList()
                     where a.Loginid == int.Parse(Session["Id"].ToString())
                     select a).FirstOrDefault();
            TempData["Name"] = v.FullName;             TempData["email"] = v.Email;             TempData["Age"] = v.Age;             TempData["Gender"] = v.Gender;             TempData["Religion"] = v.Religion;             return View();         }

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

@{
    ViewBag.Title = "Profile";
    Layout = "~/Views/Shared/_Master.cshtml";
}
<style>
    .fontbody
    {
        font-size:larger;
        font-style:italic;
    }
</style>
<h2>Profile</h2>
<div class="fontbody">
  
    <div>
        <label>@TempData["Name"]</label>
    </div>
    <div>
        Email : <label>@TempData["email"]</label>
    </div>
    <div>         Age : <label>@TempData["Age"]</label>     </div>     <div>         Religion : <label>@TempData["Religion"]</label>     </div>     <div>         Gender : <label>@TempData["Gender"]</label>     </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 one data in sql server in asp.net mvc,retrieve one data in sql server in mvc,how to retrieve one data in sql server in asp.net mvc,how to retrieve one data in sql server in mvc,Simple CRUD Operation In mvc, CRUD Operations mvc and C# in ASP.Net,CRUD with mvc,cWhat 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