0

I am using asp.net (model view controller) razor view Ajax action link to navigate through pages in my website. My requirement is i will have to restrict the user and populates some popups before navigating to different page and leaving to the current page.

suppose there is view 1 (link) i am clicking on view 1 before loading view 1 page, i will have to show some popups.. I have implemented this functionality with html action link but i want it for ajax Action link too.

Thank you,

1 Answer 1

1

You can implement OnSuccess (or OnFailure or OnBegin or OnComplete) events in JavaScipt for Ajax.ActionLink() check below code -

<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
<script type="text/javascript">
    function Test() {
        alert('hi');
    }
</script>

@Ajax.ActionLink("Rules", "LoadRules", new AjaxOptions { OnSuccess = "Test" })

Above code invokes Test JavaScript function, in there I am just alerting a message. But in your requirement, you can use some JQuery Modalpopups (or even a window.open()) to display popups for end user.

Sign up to request clarification or add additional context in comments.

8 Comments

can i call onsuccess event from onbegin event? like: @Ajax.ActionLink("Rules", "LoadRules", new AjaxOptions { OnBegin = "Test", Onsuccess="Test1" }). I don't want to write OnSuccess event on the above line but wanted to call from test function. actually there is some condition need to check on that function according to that condition i will have to open a new page. I called Test1 inside Test but it's not working
@user3369120, Why would you do that?
because i will have to ask to save values through that pop up if user click on YES button then i will navigate user to the new page else will have to stay on same page. and the same popup controls multiple pages so i can not hardcode the action method it should be dynamic.
you can assume i want to implement functionality like Do you wanted leave the page in Ajax action link mvc
@user3369120, that can be done with simple OnBegin javascript event and using a confirm dialog like return confirm('Are you sure you want to leave this page?') kind of code in OnBegin. OnSuccess will be called on the successful server call.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.