I have a razor page in which I want to display certain text if the value of the ViewData["IsActive"] is true. I'm not getting any text.
<div >
@if (ViewData["IsActive"])
{
<h2>text 1</h2>
}
else
{
<h2>text 2</h2>
}
</div>
I tried writing @{ if statement here } but still doesn't work.
I know for sure that ViewData["IsActive"] returns true.
CodePudding user response:
Please try :
<div >
@if ((bool)ViewData["IsActive"]==true)
{
<h2>text 1</h2>
}
else
{
<h2>text 2</h2>
}
</div>