You can enable multiple POST parameters using the MultiPostParameterBinding class from https://github.com/keith5000/MultiPostParameterBinding
To use it:
1) Download the code in the Source folder and add it to the web API project or any other project in the solution.
2) Use the [MultiPostParameters] attribute for action methods that must support multiple POST parameters.
[MultiPostParameters] public string DoSomething(CustomType param1, CustomType param2, string param3) { ... }
3) Add this line to Global.asax.cs in the Application_Start method before calling GlobalConfiguration.Configure (WebApiConfig.Register) :
GlobalConfiguration.Configuration.ParameterBindingRules.Insert(0, MultiPostParameterBinding.CreateBindingForMarkedParameters);
4) Ask your clients to pass parameters as properties of the object. Example JSON object for the DoSomething(param1, param2, param3) method DoSomething(param1, param2, param3) :
{ param1:{ Text:"" }, param2:{ Text:"" }, param3:"" }
JQuery example:
$.ajax({ data: JSON.stringify({ param1:{ Text:"" }, param2:{ Text:"" }, param3:"" }), url: '/MyService/DoSomething', contentType: "application/json", method: "POST", processData: false }) .success(function (result) { ... });
For more information, visit the link .
Disclaimer: I am directly related to the linked resource.
Keith Oct 26 '15 at 12:32 2015-10-26 12:32
source share