asp.net mvc - How to check TempData value in my view after a form post? -


i fill tempdata formcollection , try check value of tempdata in view mvc 4 if statement isn't working expect. here code.

controller :

[httppost] public actionresult testform(formcollection data)  {     tempdata["username"] = data["var"].tostring(); //data["var"] == "abcd"     return redirecttoaction("index"); } 

view:

@if (tempdata["var"] == "abcd")  {     <span>check</span> //never displayed } else {     @tempdata["var"]; // display "abcd" } 

this looks simple , don't understand why can't display check. can me ?

please try this

var tempval = tempdata["var"]; 

then write if statement follow

@if (tempval.tostring() == "abcd")  {     <span>check</span> //never displayed } else {     <span>@tempval</span>; // display "abcd" } 

Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -