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>
0 Comments