Home Interrupting calling data-url-action in Razor View from javascript
Reply: 1

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

Bartosz Published in 2017-09-14 10:45:30Z

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>

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) {

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?


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.

Feanaro Reply to 2017-09-14 12:31:15Z

You can try using jquery event.stopPropagation() (assuming that you're using jquery).

More details: https://api.jquery.com/event.stoppropagation/

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.303177 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO