tailieunhanh - Pro ASP.NET MVC Framework phần 9

Với mô hình Code Behind, đúng là đã có sự tách riêng giữa phần hiển thị (aspx, ascx) và các xử lý bussiness logic. Tuy nhiên người lập trình chỉ có thể làm được chuyện tách riêng phần View và Controller. Trong khi phần Model nếu không làm khéo sẽ vẫn dính chặt với vần controller và chẳng dễ test nó chút nào. | CHAPTER 12 AJAX AND CLIENT SCRIPTING 431 But sometimes you might need something more powerful because the Ajax. helpers are limited in the following ways They only do simple page updates. They can inject a finished block of HTML into your existing page but they have no support for retrieving or dealing with raw data . data in JSON format and the only way of customizing how they manipulate your DOM is by explicitly returning a JavaScript statement from your action method. When updating your DOM they simply make elements appear or disappear. There s no built-in support for making things fade or slide out or performing any other fancy animation. The programming model doesn t naturally lend itself to retaining useful behavior when JavaScript is disabled. To overcome these limitations you can write your own raw JavaScript and deal with its compatibility issues manually or make use of a full-fledged JavaScript library. For example you could directly use Microsoft s ASRNET AJAX library. However ASR NET AJAX is a heavyweight option its main selling point is its support for ASRNET WebForms complicated server-side event and control model but that s not very interesting to ASRNET MVC developers. With ASRNET MVC you re free to use any Ajax or JavaScript library. The most popular option judging by the overwhelming roar of approval coming from the world s web developers is to use jQuery. This option has become so popular that Microsoft now ships jQuery with ASRNET MVC and has said they will include it in Visual Studio 2010 even though it isn t a Microsoft product. So what s all the fuss about Using jQuery with MVC Write less do more that s the core promise of jQuery a free open source5 JavaScript library first released in 2006. It s won massive kudos from web developers on all platforms because it cuts the pain out of client-side coding. It provides an elegant CSS 3-based syntax for traversing your DOM a fluent ARI for manipulating and animating DOM elements and .