【发布时间】:2017-05-22 20:38:18
【问题描述】:
我是 ASP 和一般编程的新手,所以我可能在做一些根本上错误的事情,但它是这样的: 每次我在控制器中返回视图时,我在该控制器中使用的模型都会被清空。示例:
Account acc;
public ActionResult Index()
{
acc = new Account(accountName, password);
return View(acc)
} //At this point there still is a acc object
public ActionResult Edit(string name, string pass)
{
//Here the acc object is null
acc.userName = name;
acc.password = pass;
}
我的问题是如何访问当前正在使用的帐户或如何保存使用 de View() 发送的模型
编辑 1
当我尝试使用 TempDate 时,我仍然遇到了同样的问题:
Account acc;
public ActionResult Index()
{
acc = new Account(accountName, password);
TempDate["account"] = acc;
return View(TempDate["account"])
} //TempDate contains 1 object
public ActionResult Edit(string name, string pass)
{
//TempData is empty here
TempDate["account"].userName = name;
TempDate["account"].password = pass;
Return View("Index", TempDate["account"]);
}
【问题讨论】:
标签: c# asp.net asp.net-mvc razor