为什么此代码无法正常运行?显示链接,但是当我点击它时,请求不是异步的。相反,浏览器提出了正常的请求! :/注意:我正在使用ASP.NET MVC 4!
这是我的CSHTML块代码:
<div id="latestReviews"></div>
@Ajax.ActionLink("Click here to see the latest review", "LatestReviews", "Home", null, new AjaxOptions {
UpdateTargetId = "latestReviews",
InsertionMode = InsertionMode.InsertAfter,
HttpMethod = "GET"
})
这是我的控制器动作:
[HttpGet]
public PartialViewResult LatestReviews(){
var review = RestaurantReviewQueries.FindTheLatest(_db.Reviews, 1).Single();
return PartialView("_Review", review);
}
答案 0 :(得分:1)
最后我解决了这个问题!在_Layout.cshtml中,有一个可选的部分在视图中呈现,称为&#34;脚本&#34;。我所做的只是渲染&#34;脚本&#34;部分:
@section scripts {
<script type="text/javascript" src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
}
...
<div id="latestReviews"></div>
@Ajax.ActionLink("Click here to see the latest review", "LatestReviews", "Home", null, new AjaxOptions {
UpdateTargetId = "latestReviews",
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET"
})