In html attributes setting disabled = “disabled” not working

给你一囗甜甜゛ 提交于 2020-01-06 17:00:02

问题


@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, 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.




回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!