In my View I have some admin links that I would like to hide and show based on user role how can do this inside the view e.g.
<%= if(CHECK IF USER ROLE ADMIN) { %>
<div class="tools">
<ul>
<li class="edit"><%= Html.ActionLink("Edit", "Edit", new { id = Model.storyId }) %></li>
<li class="delete"><%= Html.ActionLink("Delete", "Delete", new { id = Model.storyId }) %></li>
</ul>
</div>
<%= } %>
@if (this.User.IsInRole("Administrator"))
{
}
<% if (Page.User.IsInRole("Admin")){ %>
<%}%>
However this is a terrible idea in my opinion. It is better to let the ViewData or Model represent what the view is to display, and the view can simply check the view data. A controller base class or an action filter can make repetitive use of this very simple and allow the code to exist in one place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With