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 it in webgrid,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))
{
<text>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)