I'm trying to pass data from a controller to view, and display these data. But after many tries I can't.
Controller code :
public ActionResult ValidSearch(ProductSearchParam gp)
{
if (gp.IsCandidate)
{
ViewBag.abc="bob";
List<ProductCandidate> prodClist = new List<ProductCandidate>();
prodClist = Pcs.SearchParam(gp,0,100);
ViewBag.total = prodClist.Count;
return View("ValidSearchCandidate", prodClist);
}
else
{
List<Product> prodlist = new List<Product>();
prodlist = Ps.SearchParam(gp,0,100);
ViewBag.total = prodlist.Count;
return View("ValidSearch", prodlist);
}
//return View();
}
View code :
<body>
<div>
<p>Bonjour @ViewBag.abc</p>
I've even try TempData
or ViewBag
, unsuccessfully.
I do not understand why the value is not getting passed to the View correctly Can someone help me to solve this ?
TempData
is notViewData
! Show how you have tried to access theViewData
property – Furlough