I have seen a few solutions here on SO, and on the old Google search. However a lot of them seem to deal with the fact that it gets disabled after it is clicked, or if it does disable them it retains the ability to click it (in effect it is just greyed out).
I've currently got the following code which, as I say, greys out the ActionLink
but it can still be clicked.
$(function DisableEnableLink() {
var addDiv = document.getElementById('addNewItemDiv');
// items is determined by logic which checks different values on the page, I have removed this logic as it works fine and isn't necessarily connected to the rest of the query.
//It returns 0 if the logic finds no items, or 'X' if it does. This will then determine whether the Action link is enabled or disabled.
if ($('items').length > 0) {
addDiv.disabled = true;
} else {
addDiv.disabled = false;
}
});
And my ActionLink
is actually contained within a div
as I can give that an ID.
<div id="addNewItemDiv">
@Html.ActionLink("Add New Item", "Add");
</div>
How can I modify what I have to have it only display text? I can't use an if statement
in the View as I'm populating data with jquery
so the page won't post back.