2015-04-12 114 views
2

我需要將視圖數據(整數)傳遞給另一個控制器。如何使用actionlink將參數傳遞給控制器​​

這是我試過的;

@Html.ActionLink("Get Location", "Index", "Map", new { [email protected]},null) 

我需要將此信息傳遞給「映射」控制器的索引操作方法;

public ActionResult Index(int? i) 
    { 
     var Id = from o in db.Objects where o.Id == i select o; 
     return View(Id); 
    } 

但該參數沒有得到通過...這是傳遞參數的方式??當我把一個斷點我發現int?我是null ..爲什麼?

+1

因爲'「id」!=「i」'。在世界的哪個地方,'我'的價值從何而來? –

回答

7

您傳遞的參數是Id,但您的操作中的參數是i。

將我重命名爲Id。

Html.ActionLink("Get Location", "Index", "Map", new { [email protected]},null) 


public ActionResult Index(int id) 
{ 
    var Id = from o in db.Objects where o.Id == id select o; 
    return View(Id); 
} 
相關問題