How to use ternary operator in Razor

Total Post:26

 1866  View(s)
Rate this:
Hi Everyone,

I have a view and i want to use ternary operator on view with the folliowing condition:
I want to check authenticity of the user if they are authenticate then doing some other task until unless doing other task with the help of User.Identity.IsAuthenticated .
Can anyone help
Thank you.

  1. Post:154

    Re: How to use ternary operator in Razor

    Hi Sachin,

    You use this:

     <a class="xxxxx">//Do your Stuff </a>
    else {
                 <a class="yyyyy">//Do your Stuff </a> 
    or we can also write like this
    <a class="@=User.Identity.IsAuthenticated ? "xxxx" : "yyyy";">//Do your Stuff</a>