asp.net-mvc-5 – Preloader Asp.net MVC

Question:

How can I make a preloader(loading…) while it is rendering the view in @RenderBody ?

In search I just found examples using Partial, but Views didn't

Any idea?

Answer:

There's not much secret:

controller

public JsonResult MinhaAction(int id)
{
    // Preenchimento de 'meuJson', e tal
    return Json(meuJson);
}

View

I'm using jQuery, and assuming you've already found a "loading" screen somewhere. I'll assume it's inside a <div> whose Id is "loading":

$('#meuLink').click(function()
{
    var action = '@Html.ResolveUrl("~/MeuController/MinhaAction/")' + $('#campoId').val();
    $('#carregando').show()
    $.getJSON(action, null, function(variavelDeCallback) 
    {
        // Faça aqui o que precisa com 'meuJson'
        $('#carregando').hide()
    });
});
Scroll to Top