2013-12-17 71 views
-1

我有一個List對象1個控制器,我想知道我怎麼能轉移到例如該下一個控制器之間傳送列表中的對象是我MVC3如何操作方法

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 

     }); 

我怎麼能轉移的東西?我迷失在此。

+1

你怎麼調用'newlist'動作? HTTP協議是無狀態的,所以如果你想發送一些值給這個控制器動作,你應該把它們包含在你的HTTP請求中。假設你已經遵守命名約定,默認模型聯編程序將負責其餘的部分。在進入ASP.NET MVC之前,瞭解HTTP協議的恕我直言絕對必須具備的先決條件。 –

回答

0

在名稱列表方法,你可以加入這一行:一旦你訪問的TempData它被清除的值

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

TempData["namelist"] = mynames; 

然後在newList方法的頂部添加此行從TempData對象