title: MVC5 how do I display a loading bar/spinning circle/loader when a function is running
body: <p>I'm using a function in MVC5/C# to send emails. However the function does take a while to run before it redirects the user to a page that says "successfully sent". So I want to display a loading window/bar to tell the user to wait till the function is done. But I'm confused as to how to implement this as most articles/questions I looked at only involves implementing this while loading a page instead of running a function.Any help or code example is appreciated, thanks.</p>
  
  <p>EDIT: This is the code I'm using to send emails</p>
  
  <pre><code>[HttpPost]
  [ValidateAntiForgeryToken]
  public async Task&lt;ActionResult&gt; sendEmails()
  { 
    var body = "Mail Content";
    var message = new MailMessage();
    message.To.Add(new MailAddress("example.mail@companydomain.com"));  // replace with valid value 
    message.From = new MailAddress("from.mail@companydomain.com");  // replace with valid value
    message.Subject = "Mail Subject";
    message.Body = body;
    message.IsBodyHtml = true;
  
    using (var smtp = new SmtpClient())
         {
             var credential = new NetworkCredential
             {
                 UserName = "from.mail@companydomain.com",  // replace with valid value
                 Password = "password"  // replace with valid value
             };
             smtp.Credentials = credential;
             smtp.Host = "smtp.office365.com";
             smtp.Port = 587;
             smtp.EnableSsl = true;
             await smtp.SendMailAsync(message);
  
          }
    return RedirectToAction("Index");
  }
  </code></pre>