2

I am using webapi2 and here is my client side code

var tbody = $('#files-table').find('tbody'); // tbody where all rows exists 
        var sortOrder = $(tbody).sortable('toArray').toString(); // geting ids of all rows 
        var updateSortOrder = $.ajax({
            url: baseUrl + 'mycontroller/updateimagesorder',
            dataType: 'json',
            traditional: true,
            contentType: 'application/json',
            data: JSON.stringify({ "sortOrder": sortOrder.split(',') }),
            type: 'PUT'
        });
        updateSortOrder.done(function (result) {
            closeModel('images-model');
        });

and here is my server side method

[Route("updateimagesorder")]
    public HttpResponseMessage PutImagesSortOrder([FromBody]string[] sortOrder) 
    {
       // do stuff with parameters 
     }

Note : /mycontroller is route prefix here and baseUrl is my domain url

so , what the issue in my code ?

1
  • What is the problem you are facing? Any error? Any unexpected behaviour? Commented Feb 6, 2014 at 9:32

1 Answer 1

3

Try passing the value like this:

data: JSON.stringify(sortOrder.split(',')),

So that your request payload looks like a string array:

["foo", "bar"]

If you want to pass the value like that:

data: JSON.stringify({ "sortOrder": sortOrder.split(',') }),

then make sure that you have declared a view model:

public class MyViewModel
{
    public string[] SortOrder { get; set; }
}

that your controller action will take as parameter:

[Route("updateimagesorder")]
public HttpResponseMessage PutImagesSortOrder(MyViewModel model) 
{
    // do stuff with parameters 
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.