Strongly typed API for ASP.NET MVC 2 asynchronous actions
I believe we have done something similar recently, if I understand you correctly. We used the JsonValueProviderFactory from the ASP.NET MVC 2 Futures library to achieve a strongly typed action (more on this at haaked.com ).
For an asynchronous action, we have something similar:
[HandleError]
public class HomeController : AsyncController
{
[HttpPost]
public void IndexAsync(Person person)
{
DoSomething();
}
public ActionResult IndexCompleted()
{
return View();
}
}
public class Person
{
public string Forename { get; set; }
public string Surname { get; set; }
}
and just POST the action with:
{"Forename": "Cheesy", "Surname": "Goat"}
There is an excellent Firefox plugin to help you test this as a "REST Client" which I would also recommend.
Hope it helps.
a source to share
MVC may very well do this, but my understanding from the code example you provided is that you want to use a json based API.
Microsoft created the WebAPI for exactly this situation, it is both strongly typed and follows the MVC pattern in its basic design, but also works well and can be used alongside third party MVC within the same web application.
But:
If you want to expose serialized objects from an MVC controller action using a simple Json serialiser package and just return the resulting string, ActionResult also supports this scenario, and messages use the built-in metadata framework to validate your data type from the message giving you the security you need.
Considering the MVC controller as a rest endpoint is also only possible to properly manipulate the controller to support typical REST calls.
I would highly recommend using WebAPI for this, as it is better suited for API scripting.
a source to share