将Id传递给模型对象 [英] Passing Id to Model Object

查看:69
本文介绍了将Id传递给模型对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用Visual Studio 3在MVC 3中处理Web应用程序,并在后端使用sql server 2005.

我正在使用HTTPPost方法在数据库中创建一个帐户。帐户创建成功。我得到了创建帐户的AccountId。

以下是给出的代码:

Hi,

I am working on web application in MVC 3 using Visual Studio 3. and using sql server 2005 at the back end.
I am creating an account in data base using the HTTPPost method. Account creates successfully. and i get the AccountId of the created account.
Here is the code given below :

[HttpPost]
       public ActionResult Index(Account account)
       {
          string accountId;
          /*
              Here is the code to create account using Linq, 
          */
          account.AccountId = accountId;

          return View("Index", account);
       }





我在调试器中检查后获得accountId然后我将accountId分配给account.AccountId属性帐户模型对象。

AccountId属性附加到视图中的文本框中,如下所示。



I get the accountId as i checked in debugger and then i assign the accountId to account.AccountId property of the Account Model object.
The AccountId property is attached to text box in the view as given below.

@Html.TextBoxFor(x => x.AccountId);



但是当重新绘制视图时,它仍然显示空框。该视图是帐户模型类的强类型视图。



请不要有人在我出错的地方立即帮助我。



提前感谢。


But when the View is redrawn it still is showing the empty box. The view is a strongly typed view of Account Model class.

No please some one help me immediately where am i going wrong.

thanks in advance.

推荐答案

请尝试如下。

Please try is as below.
@Html.DisplayFor(x => x.AccountId)


< input type =textvalue =@ Model.AccountIdid =txt_accid />

尝试这个
<input type="text" value="@Model.AccountId" id="txt_accid" />
try this


这篇关于将Id传递给模型对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆