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 8336817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:06:41+00:00 2026-06-09T04:06:41+00:00

question: I am working with jQuery sortable. I used this tutorial: http://www.xmech.net/programming/jquery-ui-sortable-tutorial/ Now this

  • 0

question:

I am working with jQuery sortable.
I used this tutorial:
http://www.xmech.net/programming/jquery-ui-sortable-tutorial/

Now this gives me a string like:

ID[]=2&ID[]=3&ID[]=4&ID[]=1

or even worse, when I call the id’s IDa_1, IDb_2, IDc_3, IDd_4 it gives me

IDb[]=2&IDc[]=3&IDd[]=4&IDa[]=1

I find this format maximum horrible and unuseful…
I want just pages : [“IDb_2”, “IDc_3”, “IDd_4”, “IDa_1”]
and have the order of the element in the array index.

To rectify this, I did:

var xxx =  { pages: $(this).sortable('toArray') };
alert(JSON.stringify(xxx));

This is my home controller:

public string SaveSortable(string pages)
{
    string strPages = Request.Params["pages"];

    Console.WriteLine(pages);
    return pages;
}


    public ActionResult Sortable()
    {
        return View();
    } // End Action Sortable

The problem is, both “pages” and strPages is always null…
It gets into the right controller though…
What am I doing wrong ?

This is my .cshtml:

@{
    Layout = null;
}

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title></title>

    <style type="text/css" media="all">
        html {margin: 0px; padding: 0px; height: 100%;}
        body {margin: 0px; padding: 0px; height: 100%;}
        input{margin: 0px; padding: 0px; }
    </style>



    <style type="text/css" media="all">

         .menu li 
         {
            list-style: none;
            padding: 10px;
            margin-bottom: 5px;
            border: 1px solid #000;
            background-color: #C0C0C0;
            width: 150px;
            display: inline;
        }
    </style>

    <script type="text/javascript" src="@Url.Content("~/Scripts/jQuery/jquery-1.7.2.min.js")"></script>  
    <script type="text/javascript" src="@Url.Content("~/Scripts/jQuery/jquery-ui/1_8_21/js/jquery-ui-1.8.21.custom.min.js")"></script>  


    <script type="text/javascript" language="javascript">

        Date.prototype.getTicksUTC = function () {
            return Date.parse(this.toUTCString()) + this.getUTCMilliseconds();
        } // End Function getTicksUTC


        var tickURL = '@Url.Content("~/Scripts/jQuery/SlickGrid/images/tick.png")';


        $(document).ready(function () {
            //$('#menu-pages').sortable();
            $("#menu-pages").sortable({
                update: function (event, ui) {
                    alert("posting");

                    //var ElementsOrder = $(this).sortable('toArray').toString();
                    var ElementsOrder = $(this).sortable('toArray');//.toString();
                    //alert(JSON.stringify(ElementsOrder));

                    var xxx =  { pages: $(this).sortable('toArray') };
                    //alert(JSON.stringify(xxx));
                    //document.writeln("<h1>"+ JSON.stringify(xxx) + "</h1>");


                    // $.post("@Url.Action("SaveSortable", "Home")?no_cache=" + new Date().getTicksUTC(), { pages: $('#menu-pages').sortable('serialize') });
                    // $.post("@Url.Action("SaveSortable", "Home")?no_cache=" + new Date().getTicksUTC(), { pages: $('#menu-pages').sortable('serialize', { key: 'id' }) });

                    $.post("@Url.Action("SaveSortable", "Home")?no_cache=" + new Date().getTicksUTC(), { pages: $(this).sortable('toArray') });

                }
            });

        });

    </script>

</head>
<body>
    <ul class="menu" id="menu-pages">
        <li id="ID_1">Home</li>
        <li id="ID_2">Blog</li>
        <li id="ID_3">About</li>
        <li id="ID_4">Contact</li>
    </ul>
</body>
</html>
  • 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-06-09T04:06:43+00:00Added an answer on June 9, 2026 at 4:06 am

    Simply use a JSON request:

    $('#menu-pages').sortable({
        update: function (event, ui) {
            $.ajax({
                url: '@Url.Action("SaveSortable", "Home")',
                type: 'POST',
                cache: false,
                contentType: 'application/json',
                data: JSON.stringify({ pages: $(this).sortable('toArray') }),
                success: function(result) {
                    // ...
                }
            });
        }
    });
    

    and then:

    [HttpPost]
    public ActionResult SaveSortable(string[] pages)
    {
        // pages will contain what you need => a list of ids
        ...
    }
    

    For the record, here’s how the JSON request POST payload will look like:

    {"pages":["ID_2","ID_3","ID_1","ID_4"]}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hopefully this is a pretty simple question! I've got the code working in jQuery
i am working on asp.net using C# and using jquery datepicker my question is,
A programmer installed jquery lightbox and everything was working fine on http://www.ozhiphopshop.com.au/sub_photos.php?id=11 I wanted
I asked this morning a question about a jQuery code that's not working (which
This might be a weird question. Anyway, I'm working on a jQuery plugin and
Based on the question jQuery code not working in IE , text/javascript is used
Working on a submit function from a jQuery dialog (based on this question). Using
I'm working on some JQuery code and I have a question about caching selectors.
I'm working just few days with jQuery, so question might be not very interesting.
While working on this question , I noticed that GCC (v4.7)'s implementation of std::function

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.