Demo Page:

ASP.NET MVC Action Filter exposes your controller’s actions as Json and Xml API endpoints. Simply decorate your controller or specific actions with the Api attribute:

public ActionResult Create(Person person)
    person.Id = Guid.NewGuid();

    return View(person);
Specify the format of your HTTP request using the Content-Type header and the expected format of the response using the Accept header.

This request sends Json and returns Json:

POST http://localhost.:33325/Home/Create HTTP/1.1
Host: localhost.:33325
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv: Gecko/20100722 Firefox/3.6.8
Accept: application/json, text/javascript, */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Content-Type: text/json; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://localhost.:33325/
Content-Length: 48
Cookie: newUser=false
Pragma: no-cache
Cache-Control: no-cache


HTTP/1.1 200 OK
Server: ASP.NET Development Server/
Date: Tue, 10 Aug 2010 23:35:27 GMT
X-AspNet-Version: 4.0.30319
X-AspNetMvc-Version: 2.0
Cache-Control: private
Content-Type: application/json; charset=utf-8
Content-Length: 92
Connection: Close


jQuery Example:
   type: "POST",
   contentType: "text/json",
   dataType: "json",
   data: "{\"FirstName\":\"Nick\",\"LastName\":\"Riggs\",\"Age\":30}",
   url: "Home/Create"

Last edited Aug 11, 2010 at 12:05 AM by nickriggs, version 10