Welcome!

Microsoft Cloud Authors: Pat Romanski, Andreas Grabner, Nick Basinger, Kevin Benedict, Liz McMillan

Related Topics: Machine Learning , Java IoT, Microsoft Cloud, Adobe Flex, Silverlight, Wearables

Machine Learning : Article

How to Hack AJAX Into the ASP.NET MVC Framework

First, I like the idea that there's an AJAX controller, I hope in the final bits it's simply called Controller

Kevin Hoffman's Blog

Before continuing on to read the rest of my post, read Nikhil's blog post.

The MVC framework for ASP.NET has been discussed in a few places, but I think the most well-known location is Scott Guthrie's blog. He's been posting sample code and information on the MVC framework and even had, last time I checked, a link to a video or two showing him discussing the MVC framework with some folks at the Microsoft campus.

There's a couple of things that I like about his sample, and a couple of things that worry me. First, I like the idea that there's an Ajax controller. I hope in the final bits it's simply called Controller and they don't make you distinguish between an Ajax controller and a regular controller - you should be able to pick and choose the functionality you want, and, well, quite frankly, I'm just sick and tired of seeing the word Ajax embedded in code. The Ajax controller should give you, as he demonstrates, the ability to render small bits of HTML. What I dislike about the Ajax nomenclature is that this functionality is useful even outside the realm of Ajax rendering and I think it should be included in the default controller.

Here's what worries me. Ajax, in enterprise applications, is not just about rendering small partial divs dynamically. Sure, that's a big part of it, but by and large when people are using an XML HTTP Request object to hit the server controller for data, they're getting raw data back, they're not usually getting a pre-rendered div. This is often the case when the controller being hit is also providing raw data to smart clients through a REST/POX/web services type of action. So, while I like the notion of RenderPartial for some scenarios, A better example would have been to render a view that outputs simple XML or, even better, JSON.

Another thing that worries me a little about the sample is that it just looks overly complex and klunky. I'll accept the notion that I have to do Ajax.Initialize() or even Ajax.RegisterScript (though, can we please drop the damn Ajax moniker from it and maybe just call it Scripting.Initialize()?? We do remember that it's not actually AjaX unless we're transmitting XML over JavaScript right? Anything else we do in the name of Ajax is just JavaScript).

MVC is all about proper separation of concerns. There's one line of code in the sample that I think is violating that, and that's the IsAjaxRequest property. This all smacks of someone attempting to make the MVC framework feel more like the old Postback world and quite frankly, the old postback world can eat my shorts. The controller, IMHO, is just a controller. It should not ever have to determine if it is rendering Ajax or rendering Regular. Ajax or regular HTML is a view decision not a controller decision. The job of the controller is to fetch the appropriate data required for rendering a view, and then pick the view to render. In my own really personal opinion, I think that the controller should remain agnostic, and if you have JavaScript calling the controller for data, the JavaScript should tweak the HTTP header (e.g. the "Accepts" header) so that the controller knows to render XML, HTML, or JSON. If you have two different kinds of HTML to render, that decision should take place inside the HTML view.

The other thing that bugs me about the IsAjaxRequest property is that it really feels like a postback. For example, is it going to work if the controller that rendered the JavaScript is the CustomerController and the controller being invoked by the XMLHTTPRequest is the OrdersController? I don't know the underlying mechanics of Nikhil's code, but it doesn't look promising.

What I really want to see from Microsoft is a really compelling reason why I shouldn't just take some off-the-shelf Ajax library and make it work with the MVC stuff. I want a really good MVC-compliant Ajax framework that doesn't make me feel like I'm being shoehorned back into the Postback world.

Anyway, it's exciting to see this stuff being worked on in the early stages and it's only going to get better from here.

tags:        
links: digg this  del.icio.us  technorati  reddit

More Stories By Kevin Hoffman

Kevin Hoffman, editor-in-chief of SYS-CON's iPhone Developer's Journal, has been programming since he was 10 and has written everything from DOS shareware to n-tier, enterprise web applications in VB, C++, Delphi, and C. Hoffman is coauthor of Professional .NET Framework (Wrox Press) and co-author with Robert Foster of Microsoft SharePoint 2007 Development Unleashed. He authors The .NET Addict's Blog at .NET Developer's Journal.

Comments (2)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


IoT & Smart Cities Stories
Codete accelerates their clients growth through technological expertise and experience. Codite team works with organizations to meet the challenges that digitalization presents. Their clients include digital start-ups as well as established enterprises in the IT industry. To stay competitive in a highly innovative IT industry, strong R&D departments and bold spin-off initiatives is a must. Codete Data Science and Software Architects teams help corporate clients to stay up to date with the mod...
There are many examples of disruption in consumer space – Uber disrupting the cab industry, Airbnb disrupting the hospitality industry and so on; but have you wondered who is disrupting support and operations? AISERA helps make businesses and customers successful by offering consumer-like user experience for support and operations. We have built the world’s first AI-driven IT / HR / Cloud / Customer Support and Operations solution.
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
Druva is the global leader in Cloud Data Protection and Management, delivering the industry's first data management-as-a-service solution that aggregates data from endpoints, servers and cloud applications and leverages the public cloud to offer a single pane of glass to enable data protection, governance and intelligence-dramatically increasing the availability and visibility of business critical information, while reducing the risk, cost and complexity of managing and protecting it. Druva's...
BMC has unmatched experience in IT management, supporting 92 of the Forbes Global 100, and earning recognition as an ITSM Gartner Magic Quadrant Leader for five years running. Our solutions offer speed, agility, and efficiency to tackle business challenges in the areas of service management, automation, operations, and the mainframe.
The Jevons Paradox suggests that when technological advances increase efficiency of a resource, it results in an overall increase in consumption. Writing on the increased use of coal as a result of technological improvements, 19th-century economist William Stanley Jevons found that these improvements led to the development of new ways to utilize coal. In his session at 19th Cloud Expo, Mark Thiele, Chief Strategy Officer for Apcera, compared the Jevons Paradox to modern-day enterprise IT, examin...
With 10 simultaneous tracks, keynotes, general sessions and targeted breakout classes, @CloudEXPO and DXWorldEXPO are two of the most important technology events of the year. Since its launch over eight years ago, @CloudEXPO and DXWorldEXPO have presented a rock star faculty as well as showcased hundreds of sponsors and exhibitors! In this blog post, we provide 7 tips on how, as part of our world-class faculty, you can deliver one of the most popular sessions at our events. But before reading...
DSR is a supplier of project management, consultancy services and IT solutions that increase effectiveness of a company's operations in the production sector. The company combines in-depth knowledge of international companies with expert knowledge utilising IT tools that support manufacturing and distribution processes. DSR ensures optimization and integration of internal processes which is necessary for companies to grow rapidly. The rapid growth is possible thanks, to specialized services an...
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
Scala Hosting is trusted by 50 000 customers from 120 countries and hosting 700 000+ websites. The company has local presence in the United States and Europe and runs an internal R&D department which focuses on changing the status quo in the web hosting industry. Imagine every website owner running their online business on a fully managed cloud VPS platform at an affordable price that's very close to the price of shared hosting. The efforts of the R&D department in the last 3 years made that pos...