我在一个控制器中有一个List对象,我想知道如何将它传输到下一个控制器,例如这就是我所拥有的
public ActionResult namelist()
{
var mynames = new List<everyname>
{
new everyname{ firstname ="john", Lastname= "henny"},
new everyname{ firstname = "bob", Lastname = "cosso"},
new everyname{ firstname = "bill", Lastname = "luther"},
new everyname{ firstname ="mike", Lastname= "jones"}
};
return View(mynames);
}
// how can i transfer the above list with information into this action below
public ActionResult newlist()
{
// i tried transfering the list here and it did not work
var namelist = new namelist()
IEnumerable<SelectListItem> items = namelist.Select(c => new SelectListItem
{
Value = namelist,
Text = namelist
});
我怎样才能转移东西?我迷失了。
答案 0 :(得分:0)
在NameList方法中,您可以添加以下行:
TempData["namelist"] = mynames;
然后在newList方法的顶部添加以下行:
var namelist = Tempdata["namelist"] as List<everyname>;
访问TempData中的值后,将从TempData对象中清除它