0

所以我有一个问题,我有两个步骤:第 1 步和第 2 步。我可以转到第 2 步,但是当我按下后第 1 步确实被加载但没有调用服务器。此问题仅存在于 IE 中。目前我使用的是 IE10,但在兼容模式下同样的问题是重复的。

我附上了一个示例项目。如果您在 HomeController 的“GetStep1”操作中放置断点。您将看到在 IE10 中按回时不会捕获断点。请让我知道我做错了什么。

在此处下载示例:http: //sdrv.ms/19mrZL7

_Layout.cshtml

<!DOCTYPE html>
<html>
<head>
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/knockout-2.3.0.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/sammy-0.7.4.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/knockout.mapping-latest.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/json2.js")" type="text/javascript"></script>
</head>

<body>
    <div class="page">
        <div id="header">
            <div id="title">
                <h1>My MVC Application</h1>
            </div>
            <div id="logindisplay">
                @Html.Partial("_LogOnPartial")
            </div>
            <div id="menucontainer">
                <ul id="menu">
                    <li>@Html.ActionLink("Home", "Index", "Home")</li>
                    <li>@Html.ActionLink("About", "About", "Home")</li>
                </ul>
            </div>
        </div>
        <div id="main">
            @RenderBody()
        </div>
        <div id="footer">
        </div>
    </div>
    @RenderSection("scripts", false)
</body>
</html>

索引.cshtml

@{
    ViewBag.Title = "Home Page";
}

<ul>
    <li id="Step-1">
        <a href="#Step1">Step1</a>
    </li>

    <li id="Step-2">
        <a href="#Step2">Step2</a>
    </li>
</ul>

<div id="dynamicData">
</div>
@section scripts{


    <script type="text/javascript">
        var IndexViewModel = function () {
            var self = this;

            self.selectedStep = ko.observable();

            Sammy(function () {
                this.get('#Step1', function () {
                    console.log('here');
                    $.ajax({
                        url: '/Home/GetStep1',
                        type: "GET",
                        success: function (result) {
                            $('#dynamicData').html(result);
                            self.selectedStep(1);
                        }
                    });
                });

                this.get('#Step2', function () {
                    $.ajax({
                        url: '/Home/GetStep2',
                        type: "GET",
                        success: function (result) {
                            $('#dynamicData').html(result);
                            self.selectedStep(2);
                        }
                    });
                });

                this.notFound = function () {
                    //console.log(location.hash);
                };

            }).run('#Step1');
        };


        ko.applyBindings(new IndexViewModel());
    </script>
}

_Step1.cshtml

<h1>Step 1</h1>
<div id="step1-view">
    <h1 data-bind="text: SelectedValue"></h1>
    <ul data-bind="foreach: Collection">
        <li data-bind="css: {'selected' : $data === $root.SelectedValue()}, click: $root.setValue"><span data-bind="text: $data"></span></li>
    </ul>
    @*<span data-bind="text: ko.toJSON($data)"></span>*@
</div>



<script type="text/javascript">
    var viewModel = ko.mapping.fromJS(@Html.Raw(Json.Encode(Model)));
    viewModel.setValue = function (item) {
        viewModel.SelectedValue(item);
    }
    ko.applyBindings(viewModel, document.getElementById("step1-view"));
</script>

家庭控制器.cs

[HttpGet]
        public ActionResult GetStep1()
        {
            return PartialView("_Step1", new Step1ViewModel());
        }

        [HttpGet]
        public ActionResult GetStep2()
        {
            return PartialView("_Step2", new Step2ViewModel());
        }
4

1 回答 1

0

将此添加到所有操作中可以解决此问题:

[OutputCache(Location = OutputCacheLocation.ServerAndClient, NoStore = true, Duration = 0, VaryByParam = "None")]
于 2013-10-10T21:26:31.427 回答