Interrupting calling data-url-action in Razor View from javascript

Viewed 772

In application we are handling button actions by putting action name and controller name in data-url-action attribute in Razor Views like below:

<button type="button" class="btn" title="Add" data-url-action="@Url.Action("Add", "Home")">
    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button>

And it works perfectly, but now I want to allow or not allow calling that action from controller. In my javascript I have function:

function setButtonsAccessibility(control) {
    if (!checkControl(control) {
        control.onclick = (function (event) {
            debugger;
            event.preventDefault();
        });
    }
}

That function catch onClick event before action from controller is called, but I have no idea how to interrupt it. That onclick function is attached when my requirements are fullfiled and here I want to prevent firing action.

I was considering to override some Razor function which recognize clicking on button with completed data-url-action as equal redirecting to pointed action, but I have no information how to find that function. Is there any possibility to solve that issue in this way or maybe is simpler solution?

event.preventDefault();

Calling mentioned above function does not solve problem.

I'm looking for generic solution, I'm not able to make hundreds changes in views - that's why I want to solve it by script.

1 Answers
Related