简体   繁体   English

ASP.NET MVC中的ASP.NET AJAX与jQuery

[英]ASP.NET AJAX vs jQuery in ASP.NET MVC

在ASP.NET MVC中哪一个更好用?

Personally I prefer jQuery for the following reasons:- 我个人更喜欢jQuery,原因如下: -

  1. The plug-in community is far more varied and attracts developers from a broad range of backgrounds (not just the MS stack). 插件社区更加多样化,吸引了众多开发人员(不仅仅是MS堆栈)。 For MS-AJAX you're pretty much constrained to the clientside AJAX control toolkit for your UI widgets at the moment. 对于MS-AJAX,您现在非常关注UI小部件的客户端AJAX控件工具包。
  2. I find the jQuery API far more applicable common clientside tasks than that offered by MS AJAX 我发现jQuery API远比MS AJAX提供的常用客户端任务更适用
  3. Given the lack of WebForms smoke and mirrors going on in MVC you sometimes need a firm control over the DOM to do certain things, the CSS selector engine offered by jQuery really helps you do this. 鉴于在MVC中缺少WebForms烟雾和镜像,你有时需要对DOM进行一定程度的控制来完成某些事情,jQuery提供的CSS选择器引擎确实可以帮助你做到这一点。

In terms of what MS AJAX offers you in MVC, it can do a lot for you in terms of giving you a quick way to "AJAXify" forms and links, but as far as I'm concerned adding 90kb worth of javascript to do that isn't really worth it when the equivalent calls in jQuery (eg $.get, $.post, $(element).load) are relatively easy to use. 就MS AJAX在MVC中为您提供的内容而言,它可以为您提供快速的“AJAXify”表单和链接,但就我而言,我需要添加价值90kb的javascript来实现这一点。当jQuery中的等效调用(例如$ .get,$ .post,$(element).load)相对容易使用时,这并不值得。

Personally, despite the HtmlHelper support for ASP.NET Ajax, I find jQuery ajax in conjunction with the JQuery forms plugin to be the nicest way to do ajax form posts in ASP.NET MVC. 就个人而言,尽管HtmlHelper支持ASP.NET Ajax,我发现jQuery ajax与JQuery表单插件一起成为在ASP.NET MVC中执行ajax表单帖子的最佳方式。

eg with a jquery call on an html product list page with a form for each product allowing the item to be added to a basket, a single line of jquery code can 'ajaxify' all the forms on the page 例如,在html产品列表页面上使用jquery调用,每个产品的表单允许将项目添加到购物篮中,单行jquery代码可以“ajaxify”页面上的所有表单

$(".productListItem form").ajaxForm({ target: '#extraInfoSection' });

combined with a simple 'IsAjaxRequest' property on a controller base class that checks the headers: 结合检查标头的控制器基类上的简单“IsAjaxRequest”属性:

Request.Headers["X-Requested-With"] == "XMLHttpRequest"

and some logic in the Controller to return the correct response type: 和Controller中的一些逻辑返回正确的响应类型:

return IsAjaxRequest ? (ActionResult) View("BasketPartial", basket) : new RedirectBackToReferrerActionResult();

you have a form that works even with javascript turned off and no ASP.NET Ajax involved. 你有一个表格即使关闭javascript工作,并没有涉及ASP.NET Ajax。

Instead of making a recommendation I suggest you read Dave Ward's blog Encosia that has a series of posts on MS Ajax/ Update Panel vs. jQuery post mechanism. 我建议您阅读Dave Ward的博客Encosia而不是提出建议,该博客在MS Ajax / Update Panel和jQuery post机制上有一系列帖子。 Dave maintains that the performance of jQuery is vastly superior as it cuts out approximately 100K from the transmission to and from the server . Dave坚持认为jQuery的性能非常优越,因为它从服务器的传输中减少了大约100K

JQuery is purely client side library. JQuery纯粹是客户端库。 Asp.Net Ajax includes both client side and server side functionalities. Asp.Net Ajax包括客户端和服务器端功能。 IMHO, comparison ain't really fair. 恕我直言,比较并不公平。 They might complement each other going by Microsoft's plans. 他们可能会根据微软的计划相互补充。

There is a variant of ASP.NET AJAX for MVC -- used with the AjaxHelper and extensions. ASP.NET AJAX for MVC有一种变体 - 与AjaxHelper和扩展一起使用。 This works well in concert with jQuery. 这与jQuery协同工作很好。 I have instances where I use both on the same page; 我有一个实例,我在同一页面上使用它们; using MVC AJAX to update a DIV based clicking a button and using jQuery to get JSON data for a different operation on the same page. 使用MVC AJAX更新基于DIV的单击按钮并使用jQuery在同一页面上获取不同操作的JSON数据。 Standard ASP.NET AJAX (UpdatePanels, etc.) should be used in the WebForms world, not in MVC. 标准ASP.NET AJAX(UpdatePanels等)应该在WebForms世界中使用,而不是在MVC中使用。

I would like to mention that Microsoft supports JQuery, and they will make support for it in upcoming versions of Visual Studio. 我想提一下,微软支持JQuery,他们将在即将推出的Visual Studio版本中支持它。 For more information please visit 有关更多信息,请访问 http://live.visitmix.com/ . http://live.visitmix.com/ ASP.NET AJAX and jQuery does not overlap much, so you would like to use both. ASP.NET AJAX和jQuery没有太多重叠,因此您希望同时使用它们。

First of all, it could be useful to take in mind that ASP.NET MVC doesn't support, or better, doesn't has the postback concept.. 首先,记住ASP.NET MVC不支持或者更好的是没有回发概念可能是有用的。

  1. asp.net ajax it's based on the post-back, server-side mechanism, it's mission it's to make more easy to integrate ajax features in a server-side mode asp.net ajax它基于post-back,服务器端机制,它的任务是更容易在服务器端模式集成ajax功能
  2. jQuery, as other frameworks (eg Extjs) implements a pure client-side ajax jQuery,因为其他框架(例如Extjs)实现了纯客户端ajax

It's still possible to use asp.net server controls in asp.net mvc, asp.net ajax it's one of them, but asp.net mvc it's made, it was thought, to separate concerns (views) and to be REST styled as close as possible, so taking this in mind the final thought would be: 它仍然可以在asp.net mvc中使用asp.net服务器控件,asp.net ajax就是其中之一,但是它被认为是asp.net mvc,它可以分离关注点(视图)并将REST样式设置为关闭尽可能地考虑到这一点,最终的想法是:

  1. Using ASP.NET Web Forms ASP.NET AJAX it's the right choiche 使用ASP.NET Web Forms ASP.NET AJAX它是正确的选择
  2. Using ASP.NET MVC it's better to try to go client, so jQuery (or others) is the better 使用ASP.NET MVC最好尝试使用客户端,因此jQuery(或其他)更好

Sorry for my english 对不起我的英语不好

将ASP.NET AJAX与Web窗体一起使用,将jQuery与ASP.NET MVC一起使用

Another alternative you probably could look at is Ajax.NET, http://www.ajaxpro.info/ . 您可能会看到的另一个替代方案是Ajax.NET, http ://www.ajaxpro.info/。 I reckon it's better than ASP.NET AJAX for WebForms. 我认为它比ASP.NET AJAX for WebForms更好。 It's runnable under MVC as well. 它也可以在MVC下运行。

First of all, you could use either, as long as when you are talking about Microsoft Ajax, you are only referring to the client library. 首先,您可以使用其中之一,只要您在谈论Microsoft Ajax时,您只是指客户端库。 You can use the MS Ajax client library and most of the toolkit extenders without any server side controls. 您可以使用MS Ajax客户端库和大多数工具包扩展程序,而无需任何服务器端控件。 I have built a pretty big application using web forms and Microsoft Ajax then converted it to MVC/jquery. 我使用Web表单构建了一个非常大的应用程序,然后Microsoft Ajax将其转换为MVC / jquery。 I found that I was using less and less of the features in the MS Ajax library. 我发现我在MS Ajax库中使用的功能越来越少。 There is so much available with plugins, that its making even the ajax toolkit obsolete. 有很多可用的插件,它甚至使ajax工具包过时。

If you are talking about MS Ajax using update panels etc, then I would say no, you can't use them in MVC. 如果你正在谈论使用更新面板等的MS Ajax,那么我会说不,你不能在MVC中使用它们。 In fact, don't use them at all! 事实上,根本不要使用它们! update panels are simulated ajax, the page still goes through its lifecylce almost defeating the purpose of using ajax. 更新面板是模拟ajax,页面仍然经历其生命周期几乎击败了使用ajax的目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM