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

  • Home
  • SEARCH
  • 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 8291789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:15:14+00:00 2026-06-08T13:15:14+00:00

So I have a table that gets transformed to an array using: var result

  • 0

So I have a table that gets transformed to an array using:

var result = $("#enrolledStudents").sortable('toArray');

But when I go a head an pass that into my controller like so:

$("#update-enroll").click(function () {
            var result = $("#enrolledStudents").sortable('toArray');
            $.ajax({
                url: '@Url.Action("Enrollment", "Classroom")',
                data: { students: result },
                type: 'POST',
                traditional: true
            });
        });

My debugging breakpoint gets set off twice, causing issues to arise. What is the proper way to submit data to my controller on POST?

  • 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-08T13:15:15+00:00Added an answer on June 8, 2026 at 1:15 pm

    Per my comments, there are a couple things that could be causing this.

    1. You have have the unobtrusive file(s) loaded multiple times
    2. Your form has an action method defined, and your button is inside the form tag as a submit button. This will submit the form, and then the click will also submit the form – see example

    Example

    <form action="/somerowout/someaction">
      <input type="text" id="text1"/>
      <input type="text" id="text1"/>
      <input type="submit" />
    </form>
    

    If you need to validate a value on your form before posting, don’t hook up an additional Ajax call. Your javascript will look something like:

    $(document).ready(function () {
        $("form").submit(function(){
            var result = $("#enrolledStudents").sortable('toArray');
            if(result == null){
                //do something to show validation failed
                return false;
            }
            return true;        
        });
    });
    

    And your form code would then look something like:

    @using (@Ajax.BeginForm(new AjaxOptions { })) { 
        <input type="text" id="text1"/>
        <input type="text" id="text1"/>
        <input type="submit" />
    }
    

    If you want to use Ajax rather than the Html Helpers, use a div instead of a form, and you won’t get a duplicate post. Here’s how you could achieve this:

    <div id="enrolledStudents">
      <--! your elements -->
      <button id="saveStudents">Save</button>
    </div>
    

    JavaScript

    $(document).ready(function () {
        $("saveStudents").click(function(){
            var result = $("#enrolledStudents").sortable('toArray');
            if(result !== null){ /* do some kind of check here. */
                $.ajax({
                    url: '@Url.Action("Enrollment", "Classroom")',
                    data: { students: result },
                    type: 'POST',
                    traditional: true,
                    success : function(data) {
                        if (data.status) {
                            window.location = data.route;
                        }               
                    }
                })
            } else {
                /* notify ui that save didn't happpen */
            }           
        });
    });
    

    Example Controller Action
    When posting your data using Ajax, here’s an example of how to pass the route

    [HttpPost]
    public ActionResult SomethingPost(SomeModel model) {
        if (Request.IsAjaxRequest()) {
            var json = new {
                       status = true,
                       route = @Url.RouteUrl("MyRouteName", new { /* route values */ })
            };
            return Json(json, JsonRequestBehavior.AllowGet);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table that gets dynamically created. When using jQuery and toggle, everything works.
I have multiple buttons that gets created in a table which all look like
I have an Excel file that gets external data from database table. I need
For example I have a dropdown box that gets a town from the table
I have a self referencing table in Oracle 9i, and a view that gets
I have those code snippet that checks the fans table and gets everyone who
I have a table view that gets refreshed two different ways. Both are through
We have a table with a Primary Key that gets populated on insert by
I've got a scenario where I have a database with one table that gets
I have a table with AIS marine data that gets updated very often. What

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.