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.
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.