I tried this:
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();
}
and it works..
so, I tried this:
[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());
}
Why it happens? Is there something wrong with the second code block?
You can pass only primitive types in redirect, you can use the
TempDatafor complicated types.Basically
TempDatais just like saving data in theSessionbut the data will be deleted automatically in the end of the request where it was read.TempDataon MSDNNotes:
C#defined private variable to be camel-case.clientinstead ofClient.List<Client>variable I would useclientsas a name instead ofclient."client"string so it won’t get out of sync, meaning one method puts the data in"Client"while the other looking for it in"client"or"Client Data"