2014-12-30 3 views
1

Я использую файл js, который дает мне всплывающее окно перед завершением сеанса пользователя. Я использую этот файл двумя способамиНевозможно вызвать функцию js file

1) В приложении для веб-форм - он работает отлично. Ниже приведен код для него. Я следую this ссылку

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 



<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server"> 
    <title>Session Time Out Warning Message</title> 

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script> 

    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script> 

    <script src="Script/timeout-dialog.js" type="text/javascript"></script> 

    <link href="css/timeout-dialog.css" rel="stylesheet" type="text/css" /> 

    <script type="text/javascript" language="javascript"> 

     function Timer(time) { 

      setTimeout(TimeOut, time); 
     } 

     function TimeOut() { 
      alert(window.location.pathname); 
      $.timeoutDialog({ 
       timeout: 0.15, 
       countdown: 60, 
       keep_alive_url: window.location.pathname, 
       logout_redirect_url: '/AutoSessionTimeOut/SessionTime.aspx', 
       restart_on_yes: true 
      }); 
     } 

    </script> 

</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:Label ID="lblMsg" runat="server" Text=""></asp:Label> 
    </div> 
    </form> 
</body> 
</html> 

CS код:

if (!IsPostBack) 
     { 
      int _displayTimeInMiliSec = (Session.Timeout - 1) * 60000; 

      if (Session["ID"] == null) 
      { 
       Session["ID"] = "New Session"; 
       lblMsg.Text = Convert.ToString(Session["ID"]); 
      } 
      else 
       lblMsg.Text = "Old Session"; 

      ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), 
       "message", 
       "<script type=\"text/javascript\" language=\"javascript\">Timer('" + _displayTimeInMiliSec + "');</script>", 
       false); 
     } 

2) Я использую его в приложении MVC.

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8" /> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <title>@ViewBag.Title - My ASP.NET Application</title> 
    @Styles.Render("~/Content/css") 
    @Scripts.Render("~/bundles/modernizr") 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js"></script> 

    <script src="Scripts/timeout-dialog.js"></script> 
    <link href="Content/timeout-dialog.css" rel="stylesheet" /> 
    <script type="text/javascript"> 

     function Timer(time) { 

      setTimeout(TimeOut, time); 
     } 

     function TimeOut() { 
      //window.location.pathname = '/Home/Index'; 
      alert(window.location.pathname); 
      alert('hi'); 
      $.timeoutDialog({ 
       timeout: 0.25, 
       countdown: 30, 
       keep_alive_url: window.location.pathname, 
       logout_redirect_url: '/Home/Index', 
       restart_on_yes: true 
      }); 

     } 


    </script> 



</head> 
<body onload="Timer(15000)"> 

    <div class="navbar navbar-inverse navbar-fixed-top"> 
     <div class="container"> 
      <div class="navbar-header"> 
       <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> 
        <span class="icon-bar"></span> 
        <span class="icon-bar"></span> 
        <span class="icon-bar"></span> 
       </button> 
       @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" }) 
      </div> 
      <div class="navbar-collapse collapse"> 
       <ul class="nav navbar-nav"> 
        <li>@Html.ActionLink("Home", "Index", "Home")</li> 
        <li>@Html.ActionLink("About", "About", "Home")</li> 
        <li>@Html.ActionLink("Contact", "Contact", "Home")</li> 
       </ul> 
       @Html.Partial("_LoginPartial") 
      </div> 
     </div> 
    </div> 
    <div class="container body-content"> 
     @RenderBody() 
     <hr /> 
     <footer> 
      <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p> 
     </footer> 
    </div> 

    @Scripts.Render("~/bundles/jquery") 
    @Scripts.Render("~/bundles/bootstrap") 
    @RenderSection("scripts", required: false) 
</body> 
</html> 

Вот когда я ставлю предупреждение как раз перед этой линией $.timeoutDialog({ как упоминанием выше, предупреждение приходит, но остальная часть кода не выполняется, и я не получаю всплывающее окно, которое я получаю в моем приложении веб-форм.

ЧТО Я делаю неправильно в MVC приложение. Пожалуйста помоги.

+0

ли становятся загружены все файлы JS? – Shiljo

+0

@ Шил: Как я могу это проверить? – user2998990

+0

используйте инструменты для скрипача, которые можно найти на http://www.telerik.com/fiddler – Shiljo

ответ

0

Я думаю timeout параметр должен быть целым числом, как упоминалось here

+0

Я попытался поставить 1200, все еще не работает. – user2998990

+0

Я просто не понять, тот же код отлично работает в веб-формах, как в ссылке, но не работает в mvc. – user2998990

Смежные вопросы