mvc2 与 ajax 表启用后退按钮

发布于 2024-12-27 17:59:53 字数 3077 浏览 1 评论 0原文

我已经创建了具有搜索表单的应用程序,下面包含搜索结果。 现在我希望能够添加历史记录、按钮返回功能。

问题是我陷入了加载页面的不定式循环中,我不知道为什么,这是在 FireFox 中。

我已按照本教程操作如何执行此操作:

http://www. asp.net/mvc/tutorials/contact-manager/iteration-7-add-ajax-functionity-cs

我的代码是:

Javascript

 <% =Html.JQuery() %>
 <script src="../../../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
 <script src="../../../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
    <script type="text/javascript">

    var _currentCaseId = -1;
    Sys.Application.add_init(pageInit);
        function OnBegin() {
            var caseId =  $("#SelectDeceased_hidden").val();

            Sys.Application.addHistoryPoint({ "caseId": caseId });

            $(document).ready(function () {
                $("#divTableContainer").html("");
            });
        }

        function OnSuccess() {
            $('#divTableContainer').fadeIn('slow');
        }

        function OnFailure() {
            alert("Something went wrong. Try again...");
        }

    function pageInit() {
        // Enable history
        Sys.Application.set_enableHistory(true);

        // Add Handler for history
        Sys.Application.add_navigate(navigate);
    }

    function navigate(sender, e) {
        // Get groupId from address bar
        var caseId = e.get_state().caseId;

        // if cases does not match
        if (_currentCaseId != caseId) {
            // assign the case id
            _currentCaseId = caseId;
            alert(caseId);
            $(document).ready(function () {

                $.ajax({
                    url: "/PostItems/UmiTable?currentCase=" 
                                             + _currentCaseId 
                                             + "&EntityType=-1",
                    success: function (data) {
                        $("#divContactList").text(data);
                    }
                });
            });
        }
    }

和我的 html

  <% using (Ajax.BeginForm("UmiTable", new AjaxOptions() { 
                                       OnFailure = "OnFailure", 
                                       OnBegin = "OnBegin", 
                                       LoadingElementId = "divLoading", 
                                       UpdateTargetId = "divTableContainer" })) %>
  <% { %>
  <% using (Html.MooseFieldWrapper("Find case", "StandardForm"))
       {  %>             
            <%= Html.CutomTextBox("Case") %>                
           <li class="Button"><input type="submit" value="Go" /></li>
    <% } %>
  <% } %>
 <div id="divLoading">     
     <div><img src="Indicator.gif" alt="loading data" />Loading</div>
 </div>
 <div id="divTableContainer"></div>

I have created my application that has search form and below contains results for the search.
Now i want to be able to add history, button back functionality.

The problem is i am caught in infinitive loop of loading page and i am not sure why, this is in FireFox.

I have followed this tutorial how to do this:

http://www.asp.net/mvc/tutorials/contact-manager/iteration-7-add-ajax-functionality-cs

My code is:

Javascript

 <% =Html.JQuery() %>
 <script src="../../../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
 <script src="../../../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
    <script type="text/javascript">

    var _currentCaseId = -1;
    Sys.Application.add_init(pageInit);
        function OnBegin() {
            var caseId =  $("#SelectDeceased_hidden").val();

            Sys.Application.addHistoryPoint({ "caseId": caseId });

            $(document).ready(function () {
                $("#divTableContainer").html("");
            });
        }

        function OnSuccess() {
            $('#divTableContainer').fadeIn('slow');
        }

        function OnFailure() {
            alert("Something went wrong. Try again...");
        }

    function pageInit() {
        // Enable history
        Sys.Application.set_enableHistory(true);

        // Add Handler for history
        Sys.Application.add_navigate(navigate);
    }

    function navigate(sender, e) {
        // Get groupId from address bar
        var caseId = e.get_state().caseId;

        // if cases does not match
        if (_currentCaseId != caseId) {
            // assign the case id
            _currentCaseId = caseId;
            alert(caseId);
            $(document).ready(function () {

                $.ajax({
                    url: "/PostItems/UmiTable?currentCase=" 
                                             + _currentCaseId 
                                             + "&EntityType=-1",
                    success: function (data) {
                        $("#divContactList").text(data);
                    }
                });
            });
        }
    }

And my html

  <% using (Ajax.BeginForm("UmiTable", new AjaxOptions() { 
                                       OnFailure = "OnFailure", 
                                       OnBegin = "OnBegin", 
                                       LoadingElementId = "divLoading", 
                                       UpdateTargetId = "divTableContainer" })) %>
  <% { %>
  <% using (Html.MooseFieldWrapper("Find case", "StandardForm"))
       {  %>             
            <%= Html.CutomTextBox("Case") %>                
           <li class="Button"><input type="submit" value="Go" /></li>
    <% } %>
  <% } %>
 <div id="divLoading">     
     <div><img src="Indicator.gif" alt="loading data" />Loading</div>
 </div>
 <div id="divTableContainer"></div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒废 2025-01-03 17:59:53

到底
我使用 jquery 历史脚本来管理导航。

in the end
i have used jquery history script to manage navigation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文