Suppose you already own the preloader
ready (html, css, js) and need only call and hide the same at the time of download
. If you don’t have, here is an example.
You can use ajax
to call his Actionresult and call his 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 on dotNetFiddle.
Edit
Using the Ajax.Actionlink you have two options Onbegin and Oncomplete. Just call the functions to show and hide the preloader
. 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>
Do you mean something thus? If it is, let me know and I’ll answer it.
– Randrade
@Randrade, I don’t understand, this is a css/js preloader
– Rod
I could explain better what the
preloader
that you refer to then?– Randrade
@Randrade hello, then, the link you sent me is a preloader in css/js...but reading my question, the preloader must have synchronized with the server processing, that is, when it finishes the process and returns the file to download, the preloader "closes"
– Rod
Yeah, I get it. I just wanted to know if the
preloader
that you referred to was just that. Post as you call theaction
for download, that tomorrow I post an answer for you, I’m on mobile now.– Randrade
ah yes...that’s exactly what I meant by preloader, so it’s a custom actionresult, it does all the processing and returns the answer that I pasted there
– Rod
You call the action by a normal link, or uses
ajax
or something like?– Randrade