My Resolution:
I resolved my issue on my own, but thought I would post the resolution for any others that are attempting something similar.
I kept the link on my menu.cshtml page as an @Html.ActionLink rather than an ajax link. But I added an onclick html attribute that called the javacript to show the spinner.
menu.cshtml
@{
ViewBag.Title = "Menu";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="container" style="text-align:center">
<div>
@Html.ActionLink("Orders", "Index", "Orders", null, new { id = "OrderLink", onclick="showPageLoadingSpinner()" })
</div>
</div>
I have the scipt for the spinner in my _Layout.cshtml partial view. which is referenced in my menu.cshtml view: Layout = "~/Views/Shared/_Layout.cshtml";
Below is my full _Layout.cshtml page including the ajax div and script references.
_Layout.cshtml
<html>
<head>
@Content.Script("jquery-1.5.1.min.js", Url)
@Content.Script("jquery.unobtrusive-ajax.min.js", Url)
</head>
<body>
<div id="ajaxLoaderDiv" style="position:fixed; top:40%; left:45%; z-index:1234; display:none;">
</div>
<div class="container">
@RenderBody()
</div>
</body>
</html>
<script type="text/javascript">
function showPageLoadingSpinner() {
$('#ajaxLoaderDiv').show();
$('#ajaxLoaderDiv').append(
'<img src="@Url.Content("~/Images/AjaxLoaderImg.gif")" alt="Loading..."class="ajax-loader" />'
);
}
function hidePageLoadingSpinner() {
setTimeout(function () {
$('.ajax-loader').remove();
$('#ajaxLoaderDiv').hide();
}, 20000);
}
</script>
This works for me because on the menu.cshtml page when you click the link the javascript will run display the spinner before the actionlink sends you to the next page. Therefore you will see the spinner while the page you are navigating to is loaded.
When the new page is ready, it will render, and display. While the new page that you are sent to (Orders/Index.cshtml) uses the same layout page which contains the ajax div, it loads the new page with the ajaxloader div property display:none set by the layout. This ends up removing the ajax spinner that was displayed while loading the page.
Therefore there is no need to ever call the javascript to hide the spinner because it is always removed when the new page renders.
Unless someone else tells me that this is an inappropriate approach and successfully show me a better way, I am going to accept this as the answer.