Skip to main content
added 10 characters in body
Source Link
shA.t
  • 17k
  • 5
  • 59
  • 121

In case someone would need - to achieve same or similar thing(like delete) via POSTPOST instead of FromUriFromUri, use FromBodyFromBody and on client side(JS/jQuery) format param as $.param({ '': categoryids }, true)$.param({ '': categoryids }, true)

c#:

public IHttpActionResult Remove([FromBody] int[] categoryIds) 

jQuery:

$.ajax({ type: 'POST', data: $.param({ '': categoryids }, true), url: url, //... }); 

The thing with $.param({ '': categoryids }, true)$.param({ '': categoryids }, true) is that it .net will expect post body to contain urlencoded value like =1&=2&=3=1&=2&=3 without parameter name, and without brackets.

In case someone would need - to achieve same or similar thing(like delete) via POST instead of FromUri, use FromBody and on client side(JS/jQuery) format param as $.param({ '': categoryids }, true)

c#:

public IHttpActionResult Remove([FromBody] int[] categoryIds) 

jQuery:

$.ajax({ type: 'POST', data: $.param({ '': categoryids }, true), url: url, //... }); 

The thing with $.param({ '': categoryids }, true) is that it .net will expect post body to contain urlencoded value like =1&=2&=3 without parameter name, and without brackets.

In case someone would need - to achieve same or similar thing(like delete) via POST instead of FromUri, use FromBody and on client side(JS/jQuery) format param as $.param({ '': categoryids }, true)

c#:

public IHttpActionResult Remove([FromBody] int[] categoryIds) 

jQuery:

$.ajax({ type: 'POST', data: $.param({ '': categoryids }, true), url: url, //... }); 

The thing with $.param({ '': categoryids }, true) is that it .net will expect post body to contain urlencoded value like =1&=2&=3 without parameter name, and without brackets.

Source Link
Sofija
  • 733
  • 11
  • 14

In case someone would need - to achieve same or similar thing(like delete) via POST instead of FromUri, use FromBody and on client side(JS/jQuery) format param as $.param({ '': categoryids }, true)

c#:

public IHttpActionResult Remove([FromBody] int[] categoryIds) 

jQuery:

$.ajax({ type: 'POST', data: $.param({ '': categoryids }, true), url: url, //... }); 

The thing with $.param({ '': categoryids }, true) is that it .net will expect post body to contain urlencoded value like =1&=2&=3 without parameter name, and without brackets.