0

Why after I submit my form the value of status_tracking is never pass. The values of the other data is pass but not with the checkboxes. How can i get the correct checkbox cheked values pass to the ajax call? for example: status_tracking = 2,3

In view:

 <input type="checkbox" name="status_tracking" id="status" value="1" />
                    <input type="checkbox" name="status_tracking" id="status" value="2" /> 
                    <input type="checkbox" name="status_tracking" id="status" value="3" /> 

                    <input type="checkbox" name="status_tracking" id="status" value="4" /> 
                </td>
                <td><button type="button" class="btn btn-primary" id="search">Search</button></td>



   $('#search').click(function () {
                var data;
                var assignment = $("#selectAssignment").val();
                var application = $("#selectApplication").val();
                var assignedTo = $("#assignedToID").val();

                 var status_tracking = $('input[name=status_tracking]:checked').map(function (_, el) {
                     return $(el).val();
                 }).get();
                // alert(status_tracking); //this get the correct value 

                $.ajax({
                    type: "GET",
                    datatype: 'html',
                    url: '',
                    data: { 'assignment': assignment, 'application': application, 'status_tracking': status_tracking, 'assignedTo': assignedTo },

                });
            });


        });

in controller:

     public ActionResult GetSearchData(string assignment, string application, string assigedTo,  string status_tracking)
        {

        }
anatp_123
  • 43
  • 6
  • https://stackoverflow.com/questions/9454645/does-id-have-to-be-unique-in-the-whole-page You do not appear to be using the id on the checkboxes, but still. – Taplar Apr 16 '19 at 20:21

1 Answers1

0

I think your data type must be "application/json" in ajax request. Url must not be empty by the way

Jack
  • 167
  • 1
  • 7
  • 1
    Are those elements checkboxes? Not sure how this relates to the problem. – Taplar Apr 16 '19 at 20:27
  • Oh I've just realized they may not. I only see the inputs which types are checkbox in given code block. I did not check the id values :) Thanks for warning :) – Jack Apr 16 '19 at 20:35