Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

if statement doesn't work in a razor page

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 class="page-login-block-info big centered">
@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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Please try :

<div class="page-login-block-info big centered">
@if ((bool)ViewData["IsActive"]==true)
{
    <h2>text 1</h2>
}
else
{
    <h2>text 2</h2>
}
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading