Windows Phone 7 Developer Launch - Learn More
kick it on DotNetKicks.com   Shout it  

Using Ajax with ASP.NET MVC

One of the features I continue to wait for from the ASP.NET MVC team is a server control library to work with the MVC framework. So as I have been working on a project using ASP.NET MVC I have begun developing my own library of server controls.

Recently, I began looking at the ExtJs library as a client-side script library for my project. I love how extensible the library is and the documentation is very good. However, there seems to be quite a bit of boiler plate code to be written for any data driven controls. So I decided to look into developing a library of controls to wrap the creation and configuration of ExtJs controls.

The main problem is that the MVC framework doesn't currently provide built-in javascript/ajax support. Sure you can do it all by hand, but I am determined that the current project I am working on will be very designer friendly. Which is one of the reasons I really like MVC - the code is moved away from the view which means away from the designer.

When developing server controls with client capabilities for the ASP.NET web forms model the controls depend heavily on the ScriptManager and ClientScriptManager classes which in turn depend upon a form element with the runat attribute set to "server". But the MVC model doesn't use a server-side form element.

However, I determined that by creating an abstraction layer I could create server controls using the same model as web forms. The abstraction layer then allows the authoring of server controls which no longer depend on the web forms model. This allows the controls to then be used for both the web forms model as well as the MVC model.

Today, I created a project on CodePlex which consists of the abstraction layer I created as well as a server control library based on the abstraction layer which encapsulates the ExtJs library.

So far, the Panel control is the only control I have authored. But over the next few weeks and months I plan to continue developing additional server controls which will make it easy to create client controls which connect to web services and WCF services by simply dragging the control to the designer and setting a view properties.

Here's just an example of how easy it is to use these server controls in your MVC or web forms project.

At the top of your aspx file include the following declaration:

<%@ Register Assembly="DevelopmentalMadness.Web.UI.ExtJsControlLibrary" Namespace="DevelopmentalMadness.Web.UI.ExtJsControlLibrary" TagPrefix="js" %>


Then anywhere in your page include the next two control declarations:

<js:extjsscriptmanager id="ScriptManager1" runat="server"/>

<js:extjspanel id="myPanel" title="control title" width="300px" runat="server" collapsible="true" html="control content"/>


And that's it. If you download the latest source code from my CodePlex project you'll see an example of using these controls in both an MVC application as well as a web forms project.

As I add new capabilities I'll write tutorials. My biggest hope is that others will use the abstraction library to write controls for other javascript libraries like JQuery or others.

Tags: , , , , , , ,

kick it on DotNetKicks.com   Shout it  

Feedback

# 

Gravatar I love the idea and i hope you extended this to include more controls, this is the way to go imo.

Thanks for all the hard work! 7/7/2008 6:52 PM | noreply@blogger.com (GD)

# 

Gravatar Thanks! I continue to add more controls to the project. It's going slower than I'd like because of other commitments. But you can continue to check back on the status of the project at http://www.codeplex.com/ajaxmvc 7/8/2008 6:53 AM | noreply@blogger.com (Mark J. Miller)

# 

Gravatar Hi Mark,

Its an amazing concept and i am following it up. Am into WCF Based REST services and jQuery, Just wanted your view on jqGrid Control (http://trirand.com/jqgrid/jqgrid.html)

-Wali. 1/16/2009 4:34 AM | noreply@blogger.com (Wali Khan)

# 

Gravatar Wali Khan,

Very nice grid control. 1/16/2009 8:31 AM | noreply@blogger.com (Mark J. Miller)

# 

Gravatar Hi Mark,

Did ya work in jqGrid? I have a problem in retrieving paging variables in wcf service like page, rows, sidx, sord...

Can u give some idea? Am stuck in paging and some related things. Rest seems fine to me right now.

Thanks in advance... :)
Wali. 2/2/2009 7:00 AM | noreply@blogger.com (Wali Khan)

# 

Gravatar No, sorry I've never used jqGrid. 2/2/2009 8:58 AM | noreply@blogger.com (Mark J. Miller)

Comments have been closed on this topic.
 

 

Copyright © Mark J. Miller