С этим тоже были проблемы. Я использую VS2013 и jquery-1.10.2.min.js. Пришлось использовать комбинацию из 4 файлов JS, чтобы заставить его работать. Надеюсь, этот пример кода кому-нибудь поможет.
Test.cshtml:
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>test</title>
<script src="@Url.Content("~/Scripts/jquery-1.10.2.min.js")" type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.history.js")" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$.history.init(function (hash) {
if (hash.length > 0) {
$("#" + hash).click();
}
},
{ unescape: ",/" });
});
function AddHashTag(hashTag) {
window.location.hash = hashTag;
}
</script>
</head>
<body>
@Ajax.ActionLink("Render Circle", "GetCircle", null,
new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "divContent", OnSuccess = "AddHashTag('circle')" },
new { @id = "circle" })
@Ajax.ActionLink("Render Diamond", "GetDiamond", null,
new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "divContent", OnSuccess = "AddHashTag('diamond')" },
new { @id = "diamond" })
@Ajax.ActionLink("Render Star", "GetStar", null,
new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "divContent", OnSuccess = "AddHashTag('star')" },
new { @id = "star" })
<div id="divContent" style="width: 300px; height: 300px; text-align: center; vertical-align: middle;
margin: 50px 50px;">
</div>
</body>
</html>
star.cshtml:
star<div class="star"></div>
diamond.cshtml:
diamond<div class="diamond"></div>
circle.cshtml:
circle<div class="circle"></div>
Home Controller:
public ActionResult Test()
{
return View();
}
[HttpGet]
public ActionResult GetCircle()
{
return PartialView("Circle");
}
[HttpGet]
public ActionResult GetDiamond()
{
return PartialView("Diamond");
}
[HttpGet]
public ActionResult GetStar()
{
return PartialView("Star");
}