所以我有一个问题,我有两个步骤:第1步和第2步。我可以转到第2步,但是当我按回第1步确实已加载,但没有拨打服务器。此问题仅出现在IE中。目前我使用的是IE10,但在兼容模式下,同样的问题是重复的。
我附上了一个示例项目。如果在HomeController中的“GetStep1”操作中放置断点。您将看到在IE10中按下时断点不会被捕获。请让我知道我做错了什么。
在此下载示例: http://sdrv.ms/19mrZL7
<!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>
@{
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>
[HttpGet]
public ActionResult GetStep1()
{
return PartialView("_Step1", new Step1ViewModel());
}
[HttpGet]
public ActionResult GetStep2()
{
return PartialView("_Step2", new Step2ViewModel());
}
答案 0 :(得分:0)
将此添加到所有操作可修复此问题:
[OutputCache(Location = OutputCacheLocation.ServerAndClient, NoStore = true, Duration = 0, VaryByParam = "None")]