Jesse Naiman tries out the latest ASP.NET MVC and other crazy code stuff like SubSonic and jquery

Wednesday, May 7, 2008

Simple ASP.NET MVC jquery ajax call

One of the coolest features of ASP.NET MVC is seeing html again and being able to manipulate it in ways that the php folks have been doing for years.

I have been guilty of forgetting that javascript and html are the key components to an ajax call and been using ajax.net instead of digging into the heart of the XMLHttpRequest Object. Fortunately a number of javascript libraries that help ease the creation of a real javascript ajax call. For this example I will be using jquery, though it is important to note that this same technique will work with any of the other javascript helper libraries available that include ajax capabilities. If you feel especially hands-on you can try this sample with the classic javascript code.

For this example you will need jquery, JSON.NET, and ASP.NET MVC Preview 3

I wanted to keep this first example as simple as possible to illustrate how easy it is to use jquery ajax instead of ajax.net. The $ operator is the heart of the jquery library, for a better explanation head over to the site and investigate, as there are numerous other articles written about this library. For this example I am going to refrain from using the $ operator everywhere because I don't want to intimidate the newcommers.

getNodeDetails(id) calls $.getJSON will send a HttpGet command to the url specified. The controller class in asp.net mvc will attempt to find an action to match the url ("NodeClicked").

Once the result is recieved from the url the function(result) portion will be run, filling the html elements with appropriate values is fairly straight forward from here. Notice how clean and friendly javascript looks using json, it's identical to the C# code...

First I grab the "id" parameter from the querystring and return a custom select statement. I tried this example without the custom select statement and ended up with a "self referencing loop" error, so I strongly advice considering what data you need and returning only the relevant fields.

Next I use JSON.NET to serialize the the node object into a json string.

Instead of using RenderView(), I use Response.Write which allows the javascript function to interpret the json result.

I'm using MVC Preview 3 and as a result the controller action requires something to be returned, so I return null. If anyone knows of a more elegant solution I would love to hear the solution.

Finally the code I am sharing is part of a larger cms project that I am working on and hope to release as an open source project eventually...but really don't we have enough custom cms solutions out there already?

*Before anyone flames me the DataContext object should not be called from the controller but for the purpose of this example I'm ignoring that piece of logic.

To get started winning at an online casino the first thing that you need to do is find one that suits your needs. After all, if you do not have an internet casino that you can wager with, you will never be able to reach your goals in the end. In order to find a casino all you have to do is start your search online. This will allow you to find several options to choose from, and also research each one. In turn, you will never have any problems finding the one that will best match your needs. [url=http://www.casinolesoleil.com]casino[/url] http://www.casinolesoleil.com casino Live-based allows you to interact with real casinos in real time. You can see, hear, and interact with live dealers and players. This works best with a high-speed internet connection. [url=http://www.redlotuscasino.com]online casino[/url] http://www.redlotuscasino.com casino Remember, before you visit any sites like these, check your local laws. Make sure that gambling and online gambling are allowed in your area. Even in different areas that allow online gambling, the rules may differ, so be sure to check the laws and rules thoroughly. Also, read all the terms, conditions, and rules of an online casino before signing up. Thanks for reading this guide! [url=http://www.triumphcasino.com]casino[/url] http://www.triumphcasino.com casino http://www.affrewards.com [url=http://www.affrewards.com]casino affiliate program[/url] Bingo is a beautiful game of luck, which involves patience, rapid coordination between hearing and searching out the numbers and lots of fun. [url=http://www.bingokisses.com]bingo[/url] [url=http://www.bingoeuphoria.com]bingo[/url] bingobingo http://www.bingokisses.com http://www.bingoeuphoria.com With online bingo your cards are randomly selected by the computer and you can play with a great number of cards sometimes as many as 100 or more. Ordinarily you will need no more than three or four cards. A display board or a caller will flash your bingo numbers and you will need to fill the pattern displayed to win the game. Some online games will have the computer automatically search and fill the numbers for you. Some people find this automation a kill-joy but some actually love the fact that all they have to do watch for the bingo flash!!! http://www.casinolesoleil.com http://www.redlotuscasino.com http://www.triumphcasino.com http://www.bingokisses.com http://www.bingoeuphoria.com http://www.pulsebet.com http://www.affrewards.com http://www.thehighrollerclub.comhttp://www.buyphentermine1.com [url=http://www.buyphentermine1.com]phentermine[/url] http://www.norxbuy.com buy phentermine

These online sports betting become widely patronized especially among the global masses. Since the globe contains a huge number of masses compared to the other two social statuses, the online sports betting is pouring a lot of money compared to Las Vegas - the betting capital of the world. [url=http://www.pulsebet.com/bg/]bet online[/url] [url=http://www.pulsebet.com/da/]bet online[/url] [url=http://www.pulsebet.com/de/]bet online[/url] [url=http://www.pulsebet.com/es]apuestas[/url] [url=http://www.pulsebet.com/fr/]jouer en ligne[/url] [url=http://www.pulsebet.com/gr]bet online[/url] [url=http://www.pulsebet.com/jp]bet online[/url] [url=http://www.pulsebet.com/nl]bet online[/url] [url=http://www.pulsebet.com/pl]bet online[/url] [url=http://www.pulsebet.com/pt]bet online[/url] [url=http://www.pulsebet.com/ro]bet online[/url] [url=http://www.pulsebet.com/ru]bet online[/url] [url=http://www.pulsebet.com/se]bet online[/url] [url=http://www.pulsebet.com/it]bet online[/url] [url=http://www.pulsebet.com/cn]bet online[/url] To get started, decide on a sport to bet on and an online sportsbook to place your wager. Selecting a wager venue used to be a very secretive mission and your betting options were limited to what an individual bookie, or book maker, was capable of covering. These limited choices resulted in odds stacked against the bettor and an apprehension when it came time for payouts. http://www.pulsebet.com/bg/ http://www.pulsebet.com/da/ http://www.pulsebet.com/de/ http://www.pulsebet.com/es/ http://www.pulsebet.com/fr/ http://www.pulsebet.com/gr/ http://www.pulsebet.com/jp/ http://www.pulsebet.com/nl/ http://www.pulsebet.com/pl/ http://www.pulsebet.com/pt/ http://www.pulsebet.com/ro/ http://www.pulsebet.com/ru/ http://www.pulsebet.com/se/ http://www.pulsebet.com/it/ http://www.pulsebet.com/cn/

Howdy just wanted to give you a brief heads up and let you know a few of the images aren't loading correctly. I'm not sure why but I think its a linking issue.I've tried it in two different browsers and both show the same results.

When one goes with a game that he does not infer, that is if you are allowed to spiel other types of games with the bonus. [url=http://www.bvfdpaydayloans.co.uk/]payday loans uk[/url] uk payday loans With over 130, players testament never get world-weary children, wish a Seven-spot Mavin Karate fist and catapult perform handstands - so all futures disputes over the TV remote restraint are settled in your favor. http://www.bvfdpaydayloans.co.uk/