Hi,
How can we pass array type data from ajax to web API.
Web API -
public HttpResponseMessage SearchFileByIDs([FromBody]string[] values)
{
.....
....
...
}
Ajax call -
- <script type="text/javascript">
- $(function () {
- $("#btnGet").click(function () {
- debugger;
- let fruits = ["5c86296afce2d453a8c27d1c", "5c86285cfbaa888204f38fd1"];
-
- $.ajax({
- url: 'http://localhost:8082/api/v1/SearchByIDS',
- type: 'POST',
- dataType: 'json',
- data:"="+ fruits,
- success: function (data, textStatus, xhr) {
- debugger;
- console.log(data);
-
- },
- error: function (xhr, textStatus, errorThrown) {
- console.log('Error in Operation');
- }
- });
- });
- });
- </script>
We get fruits id in web api parameter values -