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,

user3369120
  • 63
  • 1
  • 11

1 Answers1

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.

ramiramilu
  • 16,448
  • 5
  • 45
  • 65
  • 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 May 06 '14 at 06:28
  • @user3369120, Why would you do that? – ramiramilu May 06 '14 at 06:29
  • 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. – user3369120 May 06 '14 at 07:11
  • you can assume i want to implement functionality like Do you wanted leave the page in Ajax action link mvc – user3369120 May 06 '14 at 07:33
  • @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. – ramiramilu May 06 '14 at 07:36
  • no i want my own pop up to be display instead of jquery confirmation box' – user3369120 May 06 '14 at 07:51
  • @user3369120, I have just given you as an example, you can use your own popup there instead of regular javascript alert. It all depends on your logic in OnBegin function. – ramiramilu May 06 '14 at 07:53
  • i have created custom pop up with using jConfirm js can you help me to work on the buttons functionality similar to jquery's exit popup. – user3369120 May 06 '14 at 09:30