Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7729141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:53:38+00:00 2026-06-01T05:53:38+00:00

I am using AjaxOptions of in an Ajax ActionLink and I figured the loading

  • 0

I am using AjaxOptions of in an Ajax ActionLink and I figured the loading gif would display within the UpdateTargetId (containerDiv) and it doesn’t. I also expected the loading gif to run as long as the LoadingElementDuration, and it doesn’t. No matter duration I use – the gif loads and fades out quickly (and appears to shrink as opposed to a straight fade). Am I missing something in my code that is preventing the expected behaviour from happening?

@{
    ViewBag.Title = "Index";
}
 <script type="text/javascript">

     function OnBeginAjax() {

         var item = $("#spanBegin");
         item.text("Begin Request Fired!");

     }

     function OnCompleteAjax() {
         var item = $("#spanComplete");
         item.text("Complete Request Fired!");
     }
    </script>
<h2>Index View</h2>
<div id="spinner_container">
    <img id="spinner" src="@Url.Content("~/content/themes/base/images/ajax-loader.gif")" class="hidden"/>
</div>
<br />
<br />
<span id="spanBegin">Begin Request.....</span><br/>
<span id="spanComplete">Complete Request.....</span>
<div>
@Ajax.ActionLink(" << Fire Ajax Link", "AjaxMethod", new AjaxOptions
               {
                   UpdateTargetId = "containerDiv",
                   LoadingElementId = "spinner",
                   LoadingElementDuration = 100000,
                   OnBegin = "OnBeginAjax",
                   OnComplete = "OnCompleteAjax"

               })
</div>
<div id="containerDiv"></div>

And if what I have (and what I’m seeing) is the expected behaviour (which seems pretty useless) – any ideas on how I would pass the UpdateTargetId as a param to the OnBegin function?

Here’s the rendered HTML:

<!DOCTYPE html>
<html>
<head>
    <title>Index</title>
    <link href="/Content/Site.css" rel="stylesheet" type="text/css" />
    <script src="/Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="/scripts/jquery.unobtrusive-ajax.min.js"></script>
</head>
<h1>
    MVC Sandbox Test Site</h1>
<body>
     <script type="text/javascript">
     $(document).ready(function () {
         //            function OnBeginAjax() {
         //                alert("Begin no params");
         //                //               debugger;
         //                //               var item = $("#activityDiv");
         //            }

         //            function OnCompleteAjax() {
         //                alert("Complete no params");
         //            }
     });
     function OnBeginAjax() {
         //alert("Begin no params");
         //               debugger;
         var item = $("#spanBegin");
         item.text("Begin Request Fired!");

     }

     function OnCompleteAjax() {
         var item = $("#spanComplete");
         item.text("Complete Request Fired!");
     }
    </script>
<h2>Index View</h2>
<div id="spinner_container">
    <img id="spinner" src="/content/themes/base/images/ajax-loader.gif" class="hidden"/>
</div>
<br />
<br />
<span id="spanBegin">Begin Request.....</span><br/>
<span id="spanComplete">Complete Request.....</span>
<div>
<a data-ajax="true" data-ajax-begin="OnBeginAjax" data-ajax-complete="OnCompleteAjax" data-ajax-loading="#spinner" data-ajax-loading-duration="100000" data-ajax-mode="replace" data-ajax-update="#containerDiv" href="/Home/AjaxMethod"> &lt;&lt; Fire Ajax Link</a>
</div>
<div id="containerDiv"></div>

</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:53:39+00:00Added an answer on June 1, 2026 at 5:53 am

    I was able to customize the OnBegin function and pass in a parameter that I was able to use in the method that was called:

    <div>
    @Ajax.ActionLink(" << Fire Ajax Link", "AjaxMethod", new AjaxOptions
                   {
                       UpdateTargetId = "containerDiv",
                       LoadingElementId = "spinner",
                       LoadingElementDuration = 100000,
                       OnBegin = "OnBeginAjax('containerDiv')",
                       OnComplete = "OnCompleteAjax"
    
                   })
    </div>
    

    In the calling method, I created the jquery to add my loading.gif effect where I wanted it, and for the duration I needed.

    Ammendment:
    How to use $(this) inside MVC3 Ajax.ActionLink OnBegin,OnComplete Events

    I ended up implementing the changes found in the above answer to jquery.unobtrusive-ajax.js. IMO much cleaner solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code: <% using (Ajax.BeginForm(GetResourcesByProject, CreateRequest, new AjaxOptions { UpdateTargetId = ResourceListDiv})) { Response.Write(Html.DropDownList(SelectProject, Model.ProjectList,
@using (Ajax.BeginForm(Edit, xyz, new AjaxOptions { InsertionMode = InsertionMode.Replace, HttpMethod = POST, UpdateTargetId =
When using AjaxOptions ajaxOpts = new AjaxOptions { UpdateTargetId = Entry, LoadingElementDuration = 5000,
I am successfully using @Ajax.ActionLink to refresh data on a portion of my page,
Instead of using Html.ActionLink to load subpages into MainContent, I would like to load
i have view which looks something like this : <% using (Ajax.BeginForm(new AjaxOptions {
I created my custom Ajax.ActionLink helper (see below). I also write a summary above
I am trying to pass a Form value CustomerID (i.e.dropdownlist selected value) using Ajax.Actionlink
How would you rewrite this statement using Jquery + Ajax only? This code displays
I'm using this overload: @Ajax.ActionLink(Match, Match, User, new { userId = Model.userId, matchId =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.