Search code examples
asp.net-mvcvisibilityactionlink

Set Html.ActionLink's Visibility, Best approach ?


I have boolean value in my model and I return this model to view. I want to control actionlink visibility with this value. I found two example like this:

First

@if (Model.UserCanCreate)
{
    @Html.ActionLink("Create New", "Create")
}

Second

<li style="visibility: @Model.UserCanCreate">@Html.ActionLink("Create New", "Create")</li>

What is the best way to show/hide htmlHelpers?

Thanks.


Solution

  • The first option is the correct one.

    @if (Model.UserCanCreate)
    {
        @Html.ActionLink("Create New", "Create")
    }
    

    Never rely on visibility in the browser, give the the user only what he is allowed to see.