RestCode / WebApiProxy

MIT License
199 stars 91 forks source link

Passing a Dictionary as part of request #69

Open Evert1976 opened 8 years ago

Evert1976 commented 8 years ago

Hi,

I have this API Controller in ASPNET MVC:

public void Post([FromBody] Request request)
//...

with this request model:

public class Request
{
        public int ScenarioLocationID { get; set; }
        public int StoreLocationID { get; set; }
        public int VersionID { get; set; }
        public Dictionary<string, string> Properties { get; set; }
}

But when I try to do the following in Javascript. The Properties property has always a length of 0. Before I used the webapiproxy generator it worker ok.

var properties = {};
ko.utils.arrayForEach(self.properties(), function (impactProperty) {
    properties[impactProperty.name] = impactProperty.value;
});

var request = { 
    VersionID: self.versionID, 
    ScenarioLocationID: self.scenarioLocationId(), 
    StoreLocationID: self.storeLocationId(), 
    Properties: properties 
};

$.proxies.controller.post(request).done(function (data) {
//...

Thanks in advance,

Evert

faniereynders commented 8 years ago

Firstly, when you're saying an API Controller in MVC, are you referring to MVC 6 or Web API 2?

Currently WebApiProxy does not support MVC 6, but with a bit of hacking I'm sure you can get somewhere. Having said that, I'm assuming you're talking about Web API.

Binding with stuff like Dictionaries hasn't been officially tested and are tricky depending if you're using MVC 5 or Web API 2 because they have a completely different binding mechanism.