2016-10-06 24 views
0

我設置TempData的價值在不同的控制器之一的ActionResult,並試圖把他們的鑰匙在另一個控制器的ActionResult如何獲得TempData的伯爵或鍵入另一個的ActionResult

public ActionResult DealProducts(FormCollection form) 
{ 
    TempData["check"] = "DealUpdated"; 
} 

只是計數另一個控制器

public ActionResult CustomizedBudget() 
{ 
    var temp = TempData["doc"]; 
    var temp = TempData["doc"].Key;//like this 
    if (temp.Count > 0) // or trying to get like this, but not 
} 
+1

'TempData.ContainsKey(「doc」)'? – haim770

+0

尚未完成,你試圖做什麼! –

+0

在哪裏得到我TempData的價值'DealUpdated' – user6594294

回答

2

來分配

public ActionResult DealProducts(FormCollection form) 
{ 
    TempData["check"] = "DealUpdated"; 
} 

在CSHTML

@{ 
    TempData.Keep("check"); 
} 

在另一個控制器

public ActionResult CustomizedBudget() 
{ 
    var count = TempData.Keys.Count; 
    var DealUpdatedValue = TempData["check"]; 
} 
+0

哪裏可以得到我TempData的價值'DealUpdated' – user6594294

+0

檢查答案@Qadeer –

1

好,因爲你有

public ActionResult DealProducts(FormCollection form) 
{ 
    TempData["check"] = "DealUpdated"; 
} 

你不應該有

public ActionResult CustomizedBudget() 
{ 
    var temp = TempData["check"]; 
    var temp = TempData["check"].Key;//like this 
    if (temp.Count > 0) // or trying to get like this, but not 
} 

+0

哪裏可以得到我TempData的價值'DealUpdated' – user6594294

1

你需要以下措施來改變

public ActionResult CustomizedBudget() 
{ var temp = TempData["check"]; } 
+0

從哪裏可以得到我TempData的價值'DealUpdated' – user6594294

+0

Value in temp variable –