3
Answers

display result using MVC4

In my <strong>MVC</strong> application,<br /> i want display result (when i enter the application no in Id textbox,it will display the customer FirstName,LastName,Address in respective textboxes <br /> instead of displaying it in webgrid,in the same page by using EF.<br /><div> i am using mvc4,visual studio 2012 and EF.Thanks in advance.Can anyone please help me.</div><div>&nbsp;</div><div>&nbsp;CREATE TABLE [dbo].[tblCustomer](<br /> [Id] [int] IDENTITY(1,1) NOT NULL,<br /> [FirstName] [varchar](50) NULL,<br /> [LastName] [varchar](50) NULL,<br /> [Address] [varchar](50) NULL,<br /> CONSTRAINT [PK_tblCustomer] PRIMARY KEY CLUSTERED <br /> (<br /> [Id] ASC<br /> )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]<br /> ) ON [PRIMARY]<br /> </div><div>&nbsp; <br /><h4>Index View<br /></h4> <br /> @using (@Html.BeginForm("Index","Home",FormMethod.Post))<br /> { <br /> Enter Id :@Html.TextBox("Id")<br /> &lt;input type="submit" name="Search" value="Search" /&gt;<br /> }<br /> <br /> <strong>Home controller</strong><br /> <br /> <strong>[HttpGet]</strong><br /> public ActionResult Index()<br /> {<br /> return View();<br /> }<br /> <br /> [HttpPost]<br /> public ActionResult Index(int Id)<br /> {<br /> var qry = se.tblCustomers.Single(m =&gt; m.Id == Id);<br /> return View("_Details", qry);<br /> }<br /> <strong><br /> Details View:</strong><br /> <br /> <br /> <fieldset><legend><strong>tblCustomer</strong></legend><br /><div> @Html.DisplayNameFor(model =&gt; model.FirstName)<br /> </div> <div><br /> @Html.DisplayFor(model =&gt; model.FirstName)<br /> </div> <br /> <div><br /> @Html.DisplayNameFor(model =&gt; model.LastName)<br /> </div> <div><br /> @Html.DisplayFor(model =&gt; model.LastName)<br /> </div> <br /> <div><br /> @Html.DisplayNameFor(model =&gt; model.Address)<br /> </div> <div><br /> @Html.DisplayFor(model =&gt; model.Address)</div></fieldset></div>

Answers (3)