Friday, March 16, 2018

How to use if... else condition to show/hide text in HTML?

How to use if... else condition to show/hide text in HTML?

Here i want to Show/Hide the text in HTML page as per condition OR as per rights.

This depends on the exact details / condition that we want to use to determine if something should be displayed or not. 

For example, you could use the User.Identity.IsAuthenticated property to determine if a login user has rights to see this:

<!-- Conditionally display Show or Hide -->
<% if(User.Identity.IsAuthenticated){ %>
     <b>Show</b>
<% } else { %>
     <b>Hide</b>
<% } %>

And you also apply this in the <ul><li></li></ul> only if condition:

<ul>
              <li><a href="#">Home</a></li>
       <% if (User.Identity.IsAuthenticated){ %>
              <li><a href="#">Dashboard</a></li>

       <% } %>
</ul>

No comments:

Post a Comment