Say I have an asp.net mvc site with a page listing products. On this page, I have a “delete” button, which should only be displayed to the user who inserted the product. What is the best way to do this?
One of the ways I thought to do this was to set a boolean value in the controller to give an idea of whether the button should be displayed. Sort of:
if(IsProductOwner(UserId))
ViewData["CanDelete"] = true;
Then in the view, I can just do
<% if((boolean)ViewData["CanDelete"] == true) { %>
<% } %>
But is there a better way to do this?
source
share