loading gif in mvc

前端 未结 1 1855
抹茶落季
抹茶落季 2021-01-03 12:10

I have a method in my controller like this

public string UpdateResource()
{
    Thread.Sleep(2000);
    return string.Format(\"Current time is {0}\", DateTim         


        
1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-03 12:56

    First change to UpdateResource method. Now it returns ActionResult:

    public ActionResult UpdateResource()
    {
        Thread.Sleep(5000);
        return Content(string.Format("Current time is {0}", DateTime.Now.ToShortTimeString()));
    }
    

    We have to hide image when document is loaded so we change image tag to:

    
    

    We have added style="display:none".

    Then we are using jQuery:

    
    

    When document is loaded, we are setting click action to your button. It shows progress and then uses ajax to get ActionResult. When ActionResult comes back, we are hiding progress and setting content of #result div with returned data.

    0 讨论(0)
提交回复
热议问题