Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3594602
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:44:10+00:00 2026-05-18T19:44:10+00:00

I am using jQuery UI sortable to sort a list in the DOM. I

  • 0

I am using jQuery UI sortable to sort a list in the DOM. I succesfully have an ajax functionposting this string to my mvc action:

list[]=2&list[]=3&list[]=28&list[]=1

I’m trying to figure out how to get this serialized list of numbers into a List<int> so I can actually access them from C#.

How would I do this? I’ve already tried this method:

    [HttpPost]
    public string RoleTierUpdate( string[] form)
    {
        StringBuilder sb = new StringBuilder();

        foreach (var item in form)
        {
            sb.AppendFormat("id: {0}<br />", item);
        }

        return sb.ToString();
    }

I was thinking I could convert the array of string into a list of integers. But this returned the following output:

    id: 2
    id: ,
    id: 3
    id: ,
    id: 2
    id: 8
    id: ,
    id: 1

Is ther an easier way of getting this data into a list of int?

Edit

Here’s the code that executes the ajax post:

<script type="text/javascript">
    // Sortable
    $(document).ready(function () {
        $("#sortThis").sortable({
            handle: '.handle',
            update: function () {

                // get new order
                var order = $('#sortThis').sortable('serialize');

                // excecute ajax for db update
                $.post(
                    "/find/AdminMember/RoleTierUpdate/",
                    order,
                    function (data) {
                        $("#info").html(data);
                    }
                );

                $("#info2").html(">>" + order + "<<");
            }
        });

    });
</script>

order contains the string I showed above.

Edit 2

Updated controller to:

    [HttpPost]
    public string RoleTierUpdate( List<int> list, MemberData md) // change to List<int> list
    {
        StringBuilder sb = new StringBuilder();

        if (list != null) // added check for null
        {
            foreach (var item in list)
            {
                sb.AppendFormat("id: {0}<br />", item);
            }
        }
        else {
            sb.Append("form is null");
        }

        return sb.ToString();
    }

Updated ajax to:

    $(document).ready(function () {

        jQuery.ajaxSettings.traditional = true; // added

        $("#sortThis").sortable({
            handle: '.handle',
            update: function () {

                // get new order
                var order = $('#sortThis').sortable('serialize');

                // excecute ajax for db update
                $.post(
                    "/find/AdminMember/RoleTierUpdate/",
                    order,
                    function (data) {
                        $("#info").html(data);
                    }
                );

                $("#info2").html(">>" + order + "<<");
            }
        });

    });

The output from this is:

form is null
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T19:44:11+00:00Added an answer on May 18, 2026 at 7:44 pm

    It appears that the reason MVC’s modelbinder wasn’t willing to bind the string

    list[]=2&list[]=3&list[]=28&list[]=1 
    

    to a List<int> list is because of the “[]” in the keys. I added this javascript to my jQuery:

    // get new order
     var order = $('#sortThis').sortable('serialize');
     order = order.replace(/\[\]/gi, "")
    

    Once I took out the “[]” from the keys everything was great. The action returned this result:

    id: 2
    id: 3
    id: 28
    id: 1
    

    Which is exactly what I needed. The modelbinding to List<int> is working great.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the sortable function in jquery to sequence a faq list. Needless to
I'm using jQuery UI Sortable to make a list categorizable. I'm stuck on the
Is it possible, using jQuery Tabs (Sortable) to pre-sort them by the current day?
I have two HTML lists, and am using JQuery sortable to drag between them.
I'm using the Sortable component of jQuery UI . The callbacks don't seem to
Using jQuery, how would you find elements which have a particular style (eg: float:
I have a list of elements which I would like to make sortable and
I have a list of items like this... <ol> <li> <span></span> <img src="image.png" />
I've got a UL of items using jQuery UI that I have drag and
I am attempting to reorder a dynamically created list of CKEditors using the jQuery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.