AngularJS POST to .NET MonoRail Backend

Short post: if you’re trying to use AngularJS to $ to a .NET MonoRail backend, you’ll find that there is nothing in Request.Form, or anywhere in the Request object.

I still have refactoring to do, but the quick solution is something like below. Note the headers object and transformRequest method. This needs refactored into a friendly service, but you get the idea for now.

    method: 'POST',
    url: '/YourUrl.rails',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    transformRequest: function(data) {
        var postData = [];
        for (var prop in data)
            postData.push(encodeURIComponent(prop) + "=" + encodeURIComponent(data[prop]));
        return postData.join("&");
    data: myPostData,
}).success(function (data, status) {

Leave a Reply

Your email address will not be published. Required fields are marked *