7

Experts,

I am building a Alchemy plugin with Version: 0.7.0.0, in which I need to submit a modal with a POST request using web api proxy in JS file. I am using JS code as below as explained here .

With this, the POST request end up to the correct method of the API Controller. But all the members of the Modal are received as null.

Can someone point out, if I am making any mistake here?

Modal:

 public class MyExampleModel
    {
        public string[] Ids;
        public string comments;
        public string description;
    }  

JS code in plugin

var myCommentsModel = { Ids: ["id1", "id2", "id3"], comments: "my test comments", description: "my test description" };

Alchemy.Plugins["${PluginName}"].Api.SomeService.SomeFunction(myCommentsModel)
          .success(function (data) {
             // Some Code
          })
  • Please share your method code as well that you are trying to post. Also, did you try JSON.stringify() instead of directly constructing the json? Further, did you try without passing an array in the JSON and see if it is working – Pankaj Gaur Apr 8 '16 at 10:53
  • Can you also include the action method from the WebAPI controller that you're posting to? Thanks! – Alex Klock Apr 8 '16 at 18:47
  • Hi Pankaj, as Alex answered the problem was with the POCO class definition. I tried JSON.stringify() , it didn't work. – Saurabh Gangwar Apr 13 '16 at 18:55
2

You may have to ensure that your model, MyExampleModel, is using Pascal Casing (you can leave your JavaScript as camelcasing as it'll still serialize correctly).

More importantly, your Model should be using public getters/setters rather than just being a public field.

public class MyExampleModel
{
    public string[] Ids { get; set; }
    public string Comments { get; set; }
    public string Description { get; set; }
}  

Hope that helps! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.