Home > DeveloperSection > Forums > How to use ternary operator in Razor
Sachin Singh
Sachin Singh

Total Post:26

Posted on    March-26-2016 12:33 AM

 ASP.NET MVC C#  ASP.Net  HTML  ASP.NET MVC  HTML5  Entity Framework 

 1 Reply(s)
 379  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.

Manoj Bhatt
Manoj Bhatt

Total Post:153

Posted on    March-26-2016 8:33 AM

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>

Don't want to miss updates? Please click the below button!

Follow MindStick