Jerry Nixon @Work: Implement an AJAX form in the MVC Framework

Jerry Nixon on Windows

Monday, June 8, 2009

Implement an AJAX form in the MVC Framework

The MVC Framework (now in version 1.0) is Microsoft’s implementation of the MVC software pattern in ASP.Net.

Here, my model is using LINQ to SQL against my empty database called GLOSSARY with one table called TERMS with three columns (Id, Term, Definition). Hopefully, I have kept the scenario simple enough so you can follow me.

In this sample, I have one controller, one view, and one partial view. A partial view is basically an ASP.Net user control (even the same file extension). The partial is a list of terms. The view contains the partial and two identical forms allowing users to filter the list (one POST and one AJAX).

I hope this makes sense to you, because AJAX in MVC is pretty darn easy:

image

Get the code here: http://www.codepaste.net/ssjt1i

And now for the view(s):

image

Get the code here: http://www.codepaste.net/tdzvap