Search code examples
c#asp.netasp.net-mvcasync-awaitrazor-2

How to show modal window from controller method after 20 sec after login on any page


I should show modal window in any view page after 20 sec after login. Modal window will be saved in layout page. I would like return view asynchronously in new Task

public ActionResult Index(int Id)
{
    var viewModel = new Helper(this).GetViewModel(profile, CurrentUser);

    return View(viewModel);
}

How to call asynchronously Task that should display my modal window from this controller's method and this modal window should be available in any page of site. For example I've logined in site, but during 20 sec I can go to any controller's method but my Task that executing in Index() method should be display this modal in any current page. How to do this?


Solution

  • There's no need to call async method to manage this, simply try this in Your layout view.

    @using Microsoft.AspNet.Identity
    @if (Request.IsAuthenticated)
    {
    <script>
     $(document).ready(function() {
     setTimeout(function() {
       $('#myModal').fadeIn(200);
     }, 20 000); // milliseconds
     });
    </script>
    }