-1

我在 1 个控制器中有一个 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

        });

我怎样才能转移东西?我迷失了这一点。

4

1 回答 1

0

在 NameList 方法中,您可以添加以下行:

TempData["namelist"] = mynames;

然后在 newList 方法的顶部添加这一行:

var namelist = Tempdata["namelist"] as List<everyname>;

一旦您访问 TempData 中的值,它就会从 TempData 对象中清除

于 2013-12-17T18:31:45.583 回答