Is there a project that automatically generates JavaScript proxy code to call ASP.NET MVC action methods?

Is there any C # code that accepts an existing controller, parses its public Action methods, and generates a JavaScript proxy class so that it can be easily called with other Javascript code? I already know that we can use jquery to create $ .post and $ .get to call our ajax services, but I believe that the process can be simplified by not specifying the relative URL of the AJAX web service URL and the parameter name for each input parameters.

For example, let's say we have the following C # controller:

public class CustomerController : Controller
    {

        public JsonResult Create(string name, string address)
        {
            return new JsonResult {Data = 11111};
        }

        public JsonResult Update(int id, string name, string address)
        {
            return new JsonResult {Data = true};
        }
    }

I would like to call the action methods of the AJAX controller using the following method.

Proxy.Customer.Create("Scott Gu", "Somewhere in Redmond").done(function(id) {
      /* id is an int and not an string */
      Proxy.Customer.Update(id, "Scott Gu", "Somewhere in Seattle");
});

Is there a project that allows me to do this?

Update

, , , . -, , SignalR, Phil Haack Controller Inspector. , , , , ..

getter . https://github.com/Haacked/CodeHaacks/blob/master/src/MvcHaack.ControllerInspector/ControllerDetailer.cs

2

Doh. - JavaScript. .

+5
4

, , , SignalR ? - javascript, SignalR, MVC. , .

github , . firebug/chrome .., javascript.

, javascript, . "", , javascript .

SignalR , - - javascript .

, . , - , .

+1

, 1 . - . .

+1

This great other project allows you to do what you requested.
http://jsnet.codeplex.com/
This project automatically generates JavaScript proxies for MVC and WebApi controllers.

In this project you will also have Intellisense.

Example

window.test = function test() {
/// <summary>
///This example works.
///You have the Intellisense. It great!!!
///No hard coded url.
///</summary>

//-- settings of ajax request.
var a = $dpUrlSet.Customer.Create.$action0.$AjaxSettings();

//-- your parameters of action method
a.data.name = "Scott Gu";
a.data.address = "Somewhere in Redmond";

//-- stringify
a.data = JSON.stringify(a.data);

//-- send ajax request
var xhr = $.ajax(a);

xhr.success(function (id) {
    /// <summary>Response of ajax request</summary>

    //-- settings of ajax request.
    var a = $dpUrlSet.Customer.Update.$action0.$AjaxSettings();

    //-- your parameters of action method
    a.data.id = id;
    a.data.name = "Scott Gu";
    a.data.address = "Somewhere in Seattle";

    //-- stringify
    a.data = JSON.stringify(a.data);

    //-- send ajax request
    var xhr = $.ajax(a);

});
}
+1
source

All Articles