I have a situation where I want to display the button as enabled or disabled, depending on the property that was set in the view model.
@if (Model.CanBeDeleted)
{
<button type="button" class="btn btn-danger btn-sm">
<span class="glyphicon glyphicon-trash"> </span>
Delete
</button>
}
@if (!Model.CanBeDeleted)
{
<button disabled="disabled" type="button" class="btn btn-danger btn-sm">
<span class="glyphicon glyphicon-trash"> </span>
Delete
</button>
}
The code that is currently displayed in my view, which can be seen above, works.
However, I am looking for a way that I can only wrap an attribute disabledin an if statement, and not a separate button element for each case.
Any suggestions on how I can do this?
source
share