1
@Html.ActionLink(" ", "Edit", new { id = item.UserId }, new { title = "User is not editable" , @class = "edit_btn", disabled = "disabled"})

I want to disable ActionLink by setting html attribute disabled ="disabled", but its not working. I am able to get class and title attributes but actionLink is not getting disabled.

Can anyone help.. Where I am doing wrong.

vcsjones
  • 138,677
  • 31
  • 291
  • 286
Manish
  • 35
  • 2
  • 7

3 Answers3

5

The disabled attribute doesn't work in anchor tags. MVC renders what you expect, disabled="disabled", but browsers just ignore it.

You need to do something different, such as not rendering an anchor at all, but just render the text or in a span.

Community
  • 1
  • 1
vcsjones
  • 138,677
  • 31
  • 291
  • 286
1

Unfortunately, ActionLinks cannot be disabled using the 'disabled' attribute like a button or a select box. You could write some JavaScript that could mimic disabling a hyperlink, but I would recommend changing your html to a button or something similar instead of a hyperlink if you want to disable it.

sjager
  • 416
  • 2
  • 5
0

You can do something like this using javascript return false

@Html.ActionLink("Add Account(s)", "CreateAccount", null, new { @class = "btn btnblack", @onclick = "javascript:return false;"})
Manjay_TBAG
  • 2,176
  • 3
  • 23
  • 43