【发布时间】:2012-03-20 08:32:15
【问题描述】:
我有一个 Ajax.ActionLink 成功调用了我的控制器操作,但它没有使用返回值更新目标,而是导航到新页面并显示返回值。
我的视图中有不显眼的 ajax 脚本
<script src="../../Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
这些脚本在我的布局页面中
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
这是我的操作链接:
<span id = "status">Account is Active</span>
@Ajax.ActionLink("Deactivate",
"Deactivate",
"Lender",
new {id = Model.ID},
new AjaxOptions {
HttpMethod = "GET",
Confirm = "Confirm Deactivation",
UpdateTargetId = "status"
})
我的控制器操作:
public string Deactivate(int id) {
var status = "Account is Active";
... // call method to deactivate account
... // set status = "Account is Inactive"
return status;
}
返回值设置正确。那么为什么页面导航离开而不是做 Ajax 应该做的事情,原地不动?
【问题讨论】:
-
使用 jQuery 时不再需要 Microsoft 文件
-
@BradChristie 只是为了验证我还包含了 MicrosoftMVCAjax 文件并且它开始工作了......我很困惑为什么每个人都说不再需要这些文件并使用 jquery 来代替功能删除它们而丢失。 TekPub MVC 培训建议删除它们,Phil Haacks MVC 3 pro book 也是如此...
-
据我了解,AjaxHelper 扩展方法依赖于该库。您可以使用 jQuery 实现自己的调用(基本上是从库停止的地方开始),但它本机使用该文件。我个人对此知之甚少,我只记得我对 Ajax 和 MVC 做了什么我需要那个文件。也许抓住该文件的调试版本,看看实际使用的是什么?
-
好的,明白了,谢谢。如果您想将其添加到答案中,我会接受。
标签: asp.net-mvc-3 asp.net-ajax