jquery - MVC 中的 Ajax @Ajax。 JQuery.Ajax 中的帮助程序

标签 jquery ajax asp.net-mvc-2

我了解一点 Ajax。现在我正在学习MVC + JQuery。我想知道 MVC Ajax.Helper 和 JQuery.Ajax 中的 2 个 Ajax 是否使用相同的基础?它们与我使用 XMLHttpRequest xhr 学习的普通 Ajax 相同吗?如果没有,首选的做法是什么?我对此很陌生,并且有点困惑,所以如果我的问题对您来说没有意义,请不要介意。 谢谢你,汤姆

(已编辑)我写了一些 mvc3 Razor:

<div id="MyAjaxDiv">@DateTime.Now.ToString("hh:mm:ss tt")</div>
@Ajax.ActionLink("Update", "GetTime", new AjaxOptions { UpdateTargetId = "MyAjaxDiv", InsertionMode = InsertionMode.Replace, HttpMethod = "GET" })

当我在记事本中打开源代码时,我得到:

<div id="MyAjaxDiv">06:21:10 PM</div>
<a data-ajax="true" data-ajax-method="GET" data-ajax-mode="replace" data-ajax-update="#MyAjaxDiv" href="/Home/GetTime">Update</a>

因此,因为我只包含 ~/Scripts/jquery.unobtrusive-ajax.min.js,所以 MVC 助手必须使用 JQuery 才能工作。我的印象是他们可能需要 MicrosoftAjax.js、MicrosoftMVCAjax.js ....等,但现在看起来不像了。它们适用于 MVC2 和 aspx 页面吗?

最佳答案

这是一本 MVC 书籍的摘录,

MVC version 3 introduced support for jQuery Validation, whereas earlier versions relied on JavaScript libraries that Microsoft produced. These were not highly regarded, and although they are still included in the MVC Framework, there is no reason to use them.

JQuery 已经真正成为基于 Ajax 的请求的标准。您可能仍然使用“XMLHttpRequest xhr”方式,但 Jquery 使执行相同的操作变得更容易。

关于jquery - MVC 中的 Ajax @Ajax。 JQuery.Ajax 中的帮助程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10248644/

相关文章:

asp.net-mvc-2 - 如何创建自定义日期选择器 Html Helper?

javascript - jQuery AJAX 和 Google 货币计算器

javascript - jQuery - 替换 MyBB 消息但不是其中的一部分

jquery - CKeditor 实例为 null 或未定义?

javascript - PHP 和 Angular $http ajax 的问题

jquery - 为什么我的数组被发布为逗号分隔的字符串?

jquery - ASP.NET MVC - DropDownList 更改时刷新部分 View

c# - 在 rdlc 报告中动态隐藏列

mysql - 使用 SQL Server Express 进行小型 MVC 项目有问题吗?

jquery - 背景图像的 z-index