HOW TO USE TERNARY OPERATOR IN RAZOR

Sachin Singh

Total Post:26

Points:182
Posted by  Sachin Singh
 1320  View(s)
Ratings:
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. Manoj Bhatt

    Post:154

    Points:1086
    Re: How to use ternary operator in Razor

    Hi Sachin,

    You use this:


    @if(User.Identity.IsAuthenticated) 
     {
     <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>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!