Reputation: 27
I am new to MVC and razor. I have an MVC 4 application. In the Shared -> _Layout.cshtml page, I have some content that I would like to hide if the user in not in the allowed list. How should I proceed?
I tried using something like this, but when I look at the running code, the parts between the <% %> are commented out.
<div>
<a href="../Home/Index" style="color: White;">Home</a>
<% if(*a condition*) { %>
<a href="../Admin/Index" style="color: White;">Admin</a>
<% } %>
</div>
Thank you
Upvotes: 1
Views: 991
Reputation: 107237
If you are using razor, you just need to use @
:
<div>
<a href="../Home/Index" style="color: White;">Home</a>
@if(1==2) {
<a href="../Admin/Index" style="color: White;">Admin</a>
}
</div>
However, I would suggest you also look at using ActionLink, instead of hard coding the controller routes
Upvotes: 1