c# - Using ViewData to pass data from Controller to View -
i'm trying passing data controller view, , display these datas. after many tries 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 try tempdata or viewbag, unsuccessfully.
i not understand why value not getting passed view correctly can me solve ?
since have set property on viewdata
on controller
, have available on viewdata
on view
. on other hand, have tempdata
used when need transfer information between requests route (redirects action). sample:
public actionresult validsearch(productsearchparam gp) { list<productcandidate> prodclist = new list<productcandidate>(); viewdata["nom"] = "bob"; return view("validsearchcandidate", prodclist); }
and in view:
@viewdata["nom"].tostring() @foreach(var prod in model) { <li>@prod.name</li> }
Comments
Post a Comment