Reputation: 1950
I'm trying to toggle between enabling or disabling an html button from a Razor view based on an if statement. This disables the button regardless of the value of the if statement.
@{
disabled = "";
if (Model.User.PublicId == ViewBag.SiteUser.PublicId)
{
followClass += " you";
followText = "You";
disabled = "disabled";
}
}
<button class="@followClass" disabled="@(disabled)">@(followText)</button>
Upvotes: 1
Views: 7919
Reputation: 1574
If you want to keep the disabled in the button definition you can do the following:
<button @if (@Model.DisableButtonModel) { @("disabled='1'") }>My Button</button>
Upvotes: 0
Reputation: 1950
Simple fix, just remove disabled="" from the button definition.
<button class="@followClass" @disabled >@followText</button>
Upvotes: 2