我想用MVC4显示结果 [英] I want to display result using MVC4
问题描述
在我的MVC应用程序中,
i想要显示结果(当我在Id文本框中输入应用程序时,它将在各自的文本框中显示客户FirstName,LastName,Address
而不是在webgrid中使用EF在同一页面中显示它。
i我正在使用mvc4,visual studio 2012和EF.Thanks提前。任何人都可以帮助我。
我尝试过:
从数据库表tblCustomer创建实体框架。 ActionResult.but不按照我的期望工作。
i搜索谷歌,我发现搜索结果显示在网格中。
但是我想要,当我在Id文本框中输入应用程序时,它将在相应的文本框中显示客户FirstName,LastName,Address
而不是在webgrid中显示它,在同一页面中使用EF。
Sq;表:
CREATE TABLE [dbo]。[tblCustomer](
[Id] [int] IDENTITY(1,1)NOT NULL ,
[FirstName] [varchar](50)NULL,
[LastName] [varchar](50)NULL,
[地址] [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]
索引浏览:
索引
@using(@ Html.BeginForm(Index) ,Home,FormMethod.Post))
{
< text>输入Id:@ Html.TextBox(Id)
< input type =submitname =Searchvalue =Search/>
}
家庭控制器< br $>
[HttpGet]
公共ActionResult索引()
{
返回查看();
}
[HttpPost]
公共ActionResult索引(int Id)
{
var qry = se.tblCustomers.Single(m => m.Id == Id);
返回查看(_详情,qry);
}
详情查看:
tblCustomer
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.DisplayNameFor(model => model.FirstName)
@ Html.DisplayFor(model => model.FirstName)
@Html.DisplayFor(model => model.FirstName)
@ Html.DisplayNameFor(model => model.LastName)
@Html.DisplayNameFor(model => model.LastName)
@ Html.DisplayFor(model => model.LastName)
@Html.DisplayFor(model => model.LastName)
@ Html.DisplayNameFor(model => model.Address)
@Html.DisplayNameFor(model => model.Address)
@ Html.DisplayFor(model => model.Address)
@Html.DisplayFor(model => model.Address)
< br>
推荐答案
为了在各个文本框中显示结果,请使用TextBoxFor而不是DisplayFor。
详细信息视图中需要更改PFB。
详情查看:
@model CodePrjctQues.Models.tblCustomer
@ {
ViewBag.Title =Details;
}
详细信息
tblCustomer
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.DisplayNameFor(model => model.FirstName)
@ Html.TextBoxFor(model => model.FirstName)
@Html.TextBoxFor(model => model.FirstName)
@ Html.DisplayNameFor(model => model.LastName)
@Html.DisplayNameFor(model => model.LastName)
@ Html.TextBoxFor(model => model.LastName )
@Html.TextBoxFor(model => model.LastName)
@Html。 DisplayNameFor(model => model.Address)
@Html.DisplayNameFor(model => model.Address)
@ Html.TextBoxFor(model => model.Address)
@Html.TextBoxFor(model => model.Address)
我希望这将解决您的问题。
I hope this will solve your problem.
这篇关于我想用MVC4显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!