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?
Per my comments, there are a couple things that could be causing this.
Example
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:
And your form code would then look something like:
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:
JavaScript
Example Controller Action
When posting your data using Ajax, here’s an example of how to pass the route