AJAX Get Request using ASP.NET MVC & Prototype

I have been itching to work with ASP.NET MVC since first preview came out. In past I have used ROR and MonoRail frame work for prototyping small sample applications. I was really impressed with AJAX implementation in both frameworks, so it seemed logical to start with AJAX, However to make it more interesting I decided to use Prototype Javascript Framework instead of Microsoft AJAX implementation.

About Prototype

Prototype JavaScript Framework enables you to deal with Ajax calls in a very easy way and it is also cross-browser. It provides few simple functions to encapsulate AJAX request.

Simple MasterDetail Page.

Very simple master detail page which will display list of users, when you click on "Show Details" link it will display user details. It’s simple and done lot of time before but this time we will do that with Prototype and ASP.NET MVC Framework.

Simple Master detail page 

The Controller

I have a User controller which has two actions, Index action is responsible for getting list of users and UserDetail action is responsible for getting single user.

Simple AJAX Controller

The User listing View

I have Index.aspx view in /Views/SimpleAjax folder, this view is responsible for displaying list of users and link to JavaScript function which renders user details. I have used Ajax.Updater function to call remote page. Ajax.Updater can make request to remote page to receive HTML fragment that updates parts of the document.

 User Listing View

The User Detail View

Finally I have User.aspx view in /Views/SimpleAjax folder it can be used  as either partial view or AJAX callable, this view will simply spit out HTML without html,head and body tags.

User View

What’s Next

Instead of calling Prototype functions directly you also can create UI Helper methods to emit appropriate JavaScript and HTML. I will try to touch on UI Helper methods and more AJAX samples with prototype in my future blogs.

Full sample source code is available here

Published Saturday, January 26, 2008 11:38 PM by jigar

Comments

# re: AJAX Get Request using ASP.NET MVC & Prototype

Sunday, January 27, 2008 6:46 AM by coreware

Very nice explanation of prototype+asp.net MVC, thanks for sharing this!

# re: AJAX Get Request using ASP.NET MVC & Prototype

Wednesday, July 09, 2008 2:17 AM by jim

However, in VS2008 + MVC3.5 environment, builed failed, error:

ExperimentsWithMVCAJAX\ExperimentsWithMVCAJAX\Controllers\HomeControlle

# ASP.NET MVC Archived Buzz, Page 1

Thursday, September 04, 2008 6:25 AM by ASP.NET MVC Archived Buzz, Page 1

Pingback from  ASP.NET MVC Archived Buzz, Page 1

# re: AJAX Get Request using ASP.NET MVC & Prototype

Monday, November 03, 2008 9:35 AM by Rem

The blog is helpfull...

visit also asp.net examples

# re: AJAX Get Request using ASP.NET MVC & Prototype

Sunday, February 15, 2009 9:42 PM by Jonathan

I updated this to work with RC1

www.ranessoftwareconsulting.com/.../ajax-with-mvc-rc1

I have decided I am using Prototype for all my MVC Ajax

Leave a Comment

(required) 
(required) 
(optional)
(required)