greddin
asked on
ASP.NET Razor Newbie Question
How do I check if a session variable is true? I keep getting an error saying it cannot convert object to bool.
I've tried something like this:
@if (Session["myVariable"] == true) {
Do something
}
I've tried something like this:
@if (Session["myVariable"] == true) {
Do something
}
ASKER
Thanks kaufmed:
The syntax you give above compiles without error but gives me this error on the page:
"Object reference not set to an instance of an object"
Any ideas?
The syntax you give above compiles without error but gives me this error on the page:
"Object reference not set to an instance of an object"
Any ideas?
Something is null. You'll have to figure out what. If you can post the code, then I can take a gander.
ASKER
It looks like this:
@if ((bool)Session["isSuperAdm in"] == true) {
<li><a href="#">Admin Link</a></li>
}
isSuperAdmin is a bit/boolean field from SQL. 0 or 1
@if ((bool)Session["isSuperAdm
<li><a href="#">Admin Link</a></li>
}
isSuperAdmin is a bit/boolean field from SQL. 0 or 1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That worked. I really appreciate your help.
Open in new window