问题
@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.
回答1:
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
.
回答2:
Unfortunately, ActionLink
s 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.
回答3:
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;"})
来源:https://stackoverflow.com/questions/30605082/in-html-attributes-setting-disabled-disabled-not-working