If statement doesn't work in a razor page

Posted by: talent-letdown.0c on 30 August 2022, 10:27 pm EST

    • Post Options:
    • Link

    Posted 30 August 2022, 10:27 pm EST

    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.

    @if (ViewData["IsActive"]) {

    text 1

    } else {

    text 2

    }
    I tried writing @{ if statement here } but still doesn't work.

    I know for sure that ViewData[“IsActive”] returns true.

  • Posted 1 September 2022, 2:27 am EST

    HI,

    Please use the following code snippet:

    @if(bool.Parse(ViewData["isActive"].ToString())) {
        <h2>test</h2>  
    }
    else {
        <h2>test fail</h2>
    }
    
    

    It works for us and should work for you too !!!

    Regards,

    Manish Gupta

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels