Let's say you already have preloader
ready (html, css, js) and need only call and hide it at download
time. If you do not have it, here is an example.
You can use ajax
to call your ActionResult and call your preloader ao mesmo tempo.
<script>
$(".downloadAnexo").click(function () {
$("#divPreloader").fadeIn();//Chama o preloader
$.ajax({
url: '@Url.Action("DownloadFile")?id=' + 1,//Sua ActionResult
type: 'GET',
success: function () {
$("#divPreloader").hide();//Esconde o preloader em caso de sucesso
}, error: function () {
$("#divPreloader").hide();//Esconde o preloader em caso de erro
}
});
});
</script>
See an example at dotNetFiddle.
Edit
Using the Ajax.ActionLink you have both the OnBegin and OnComplete options. Just call the functions to show and hide preloader
. It would look like this:
@Ajax.ActionLink("Print", "Index", new { id = 20 }, new AjaxOptions
{
Confirm = "Are you cure?",
HttpMethod = "GET",
LoadingElementId = "divLoading",
OnBegin = "onAjaxBegin",//Chamo a função onAjaxBegin
OnComplete = "onAjaxComplete"//Quando completar, chamo a função onAjaxComplete
})
And you create the functions to do what you want:
<script>
function onAjaxBegin() {
$('#divPreloader').fadeIn();
}
function onAjaxComplete() {
$('#divPreloader').hide();
}
</script>