Search code examples
asp.net-coretag-helpers

ASP.net Core Conditional disable icon


Having tried what feels like everything, including the following, I can't find a way of disabling the edit icon based on a condition.

<a asp-action="Edit" asp-route-id="@item.Id" disabled="@ViewBag.status">
  <i class="fas fa-edit disabled" style="color:darkolivegreen" title="Edit Bundle" disabled="@ViewBag.status"></i>
</a>


Solution

  • I wrapped two button options: one enabled and a one disabled in an if(){} and that worked, although not very elegant. Here is the code:

    <div class="form-group">
      @{
        if (ViewBag.missing == 0)
        {
          <input type="submit" class="btn btn-primary" disabled="disabled" value="Select Node(s)" />
        }
        else
        {
          <input type="submit" class="btn btn-primary" value="Select Node(s)" />
        }
      }
    </div>