本文介绍了要从控制器动作方法中获取tempdata值的代码是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Controller Action方法代码:
Controller Action method code :
[HttpGet]
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(FormCollection formCollection)
{
Employee employee = new Employee();
// Retrieve form data using form collection
employee.Name = formCollection["Name"];
employee.Gender = formCollection["Gender"];
employee.City = formCollection["City"];
employee.DateOfBirth = Convert.ToDateTime(formCollection["DateOfBirth"]);
businesslayer.AddEmmployee(employee);
TempData["Employees"] = employee;
return RedirectToAction("Testtempdata");
}
public ActionResult Testtempdata()
{
Employee employee = TempData["Employees"] as Employee;
return View(employee);
}
与Actionmethods相关的视图:
Views Related to Actionmethods:
Index View:
{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@Html.ActionLink("Testtempdata","Testtempdata")
Tempdata视图:
Tempdata view:
@model
@{
ViewBag.Title = "Testtempdata";
}
<h2>Testtempdata</h2>
@{Html.BeginForm("Testtempdata", "Testtempdata", FormMethod.Post);}
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td class="inner_databg">
</td>
</tr>
<tr>
</tr>
</table>
这里在TEmpdata视图中我想检索tempdata值。通过员工对象获取我需要在tempdataview中编写的代码。
有人帮助我
提前感谢:
Here In TEmpdata view i would like to retrieve the tempdata values. getting by employee object what code i need to write in tempdataview.
Some one help me
Thanks in advance:
推荐答案
@model Employee
@{
ViewBag.Title = "Testtempdata";
}
//then you can access employee values like this
<p>@Model.EmployeeProperty1</p>
希望这有帮助
Hope this helps
这篇关于要从控制器动作方法中获取tempdata值的代码是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!