Click here to Skip to main content
15,885,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In my MVC application,
i want display result (when i enter the application no in Id textbox,it will display the customer FirstName,LastName,Address in respective textboxes
instead of displaying in webgrid,i want to display record in the same page by using EF.
i am using mvc4,visual studio 2012 and EF.Thanks in advance.Can anyone please help me.

What I have tried:

created Entity framework from database table "tblCustomer".Created one ActionResult.but not working as per my expectation.
i searched in google,i found after search result displayed in the webgrid.

but i want,when i enter the application no in Id textbox,it will display the customer FirstName,LastName,Address in respective textboxes
instead of displaying it in webgrid,in the same page by using EF.
Sq; Table:
CREATE TABLE [dbo].[tblCustomer](
[Id] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [varchar](50) NULL,
[LastName] [varchar](50) NULL,
[Address] [varchar](50) NULL,
CONSTRAINT [PK_tblCustomer] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

Index View:
Index

@using (@Html.BeginForm("Index","Home",FormMethod.Post))
{
Enter Id :@Html.TextBox("Id")
<input type="submit" name="Search" value="Search" />
}

Home controller

[HttpGet]
public ActionResult Index()
{
return View();
}

[HttpPost]
public ActionResult Index(int Id)
{
var qry = se.tblCustomers.Single(m => m.Id == Id);
return View("_Details", qry);
}

Details View:


tblCustomer



@Html.DisplayNameFor(model => model.FirstName)

@Html.DisplayFor(model => model.FirstName)


@Html.DisplayNameFor(model => model.LastName)

@Html.DisplayFor(model => model.LastName)


@Html.DisplayNameFor(model => model.Address)

@Html.DisplayFor(model => model.Address)
Posted
Updated 9-Aug-16 19:57pm
v2

1 solution

In order to display the result in respective textboxes, kindly use TextBoxFor instead of DisplayFor.

PFB changes required in Details View.

Details View:


@model CodePrjctQues.Models.tblCustomer

@{
ViewBag.Title = "Details";
}

Details




tblCustomer


@Html.DisplayNameFor(model => model.FirstName)


@Html.TextBoxFor(model => model.FirstName)



@Html.DisplayNameFor(model => model.LastName)


@Html.TextBoxFor(model => model.LastName)



@Html.DisplayNameFor(model => model.Address)


@Html.TextBoxFor(model => model.Address)




I hope this will solve your problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900