What i need to do is check if TEMPDATA["projectCode"] exists and if it does exist get the value, and if the value is > 0, place it in a VIEWBAG. If it does not exist, and then dont put anything in the VIEWBAG (which gets passed onto a VIEW())
When the data is available, it does get put into the TempData space and i can use that in my VIEW. its just that, i do not want to output the text that is appended to the TempData if if doesnt exist.
ngokal
Member
132 Points
221 Posts
IF statement not working with TempData. How to access the actual Value so to be used in condition...
Mar 22, 2012 11:57 AM|LINK
Hi,
I am trying to do the following but getting an error. How do i do an IF statment using TEMPDATA?
im trying to do this: The error is : Operator > cannot be applied to to operands of type object. I need to access the value of TEMPDATA
adamturner34
Contributor
4394 Points
1102 Posts
Re: IF statement not working with TempData. How to access the actual Value so to be used in condi...
Mar 22, 2012 11:59 AM|LINK
What is temp data? Convert it to int.
ngokal
Member
132 Points
221 Posts
Re: IF statement not working with TempData. How to access the actual Value so to be used in condi...
Mar 22, 2012 12:11 PM|LINK
Ive tried doing that as per below, but if it is null, it fails and gives me a nullReferenceException
ignatandrei
All-Star
137670 Points
22146 Posts
Moderator
MVP
Re: IF statement not working with TempData. How to access the actual Value so to be used in condi...
Mar 22, 2012 12:21 PM|LINK
TempData is not Session. TempData gets removed after first retrieving( you can TempData.Keep , however)
ngokal
Member
132 Points
221 Posts
Re: IF statement not working with TempData. How to access the actual Value so to be used in condi...
Mar 22, 2012 12:31 PM|LINK
What i need to do is check if TEMPDATA["projectCode"] exists and if it does exist get the value, and if the value is > 0, place it in a VIEWBAG. If it does not exist, and then dont put anything in the VIEWBAG (which gets passed onto a VIEW())
When the data is available, it does get put into the TempData space and i can use that in my VIEW. its just that, i do not want to output the text that is appended to the TempData if if doesnt exist.
ignatandrei
All-Star
137670 Points
22146 Posts
Moderator
MVP
Re: IF statement not working with TempData. How to access the actual Value so to be used in condi...
Mar 22, 2012 12:52 PM|LINK
TempData.ContainsKey("projectCode")
ngokal
Member
132 Points
221 Posts
Re: IF statement not working with TempData. How to access the actual Value so to be used in condi...
Mar 22, 2012 01:14 PM|LINK
Great,
it works
Thank you