之間傳遞我嘗試這樣做:參數動作
public ActionResult Index() // << it starts here
{
return RedirectToAction("ind", new { name = "aaaaaaa" });
}
[ActionName("ind")]
public ActionResult Index(string name)// here, name is 'aaaaaaa'
{
return View();
}
和它的作品..
所以,我嘗試這樣做:
[HttpPost]
public ActionResult Search(string cnpj) // starts here
{
List<Client> Client = db.Client // it always find one client
.Where(c => cnpj.Equals(c.Cnpj))
.ToList();
return RedirectToAction("Index", Client); // client is not null
}
public ActionResult Index(List<Client> Client) //but when goes here, client is always null
{
if (Client != null)
return View(Client);
return View(db.Client.ToList());
}
爲什麼會發生?第二個代碼塊有問題嗎?
它承擔提的是,這些都是很大的不同approches各地傳遞數據。默認情況下使用臨時數據提供程序將數據存儲在會話中。另外,當你回來時,臨時數據並不保證在那裏。可能考慮執行操作而不是重定向,而不是重定向,而不是重要 - 在這個主題上,POST是必需的嗎?搜索結果通常是更好地得到... – Paul 2012-04-19 18:01:54
@保羅處理。我想我在答案中提到了它,但謝謝澄清這些缺點! – gdoron 2012-04-19 18:03:49
啊,在我開始寫作時沒有看到你的更新... – Paul 2012-04-19 18:04:27