-1

I need to pass a few parameters from view to Controller using JavaScript AJAX.

Following is my code for the JavaScript:

<script>
    $(document).ready(function () {
        $('#PaidMonth').on('change', function () {
            var deviceid = $('#PaidMonth').val();
            alert(deviceid);
            $.ajax({
                type: 'GET',
                data: { PaidMonth: deviceid },
                url: 'http://localhost:8089/HRM/PaidSalary/id?EmpName',
                dataType: 'json',
                success: function (data) {
                    console.log(JSON.stringify(data))
                    vehicle = $("#MonthOfSalary").val();
                    console.log(vehicle);
                },
                async: true // make it true if you want to make an async call.
            });
        });
    });
</script>

I need to pass the data to controller:

public ActionResult PaidSalary(Int64 id, String EmpName, DateTime? PaidMonth)

I need id, Empname, PaidMonth which I will be passing from the View.

Also, please don't mark the question as Duplicate as I am not able to find appropriate result.

5
  • 2
    deviceid need to be in datetime format Commented Nov 3, 2018 at 6:24
  • 1
    or else take PaidMonth as string and convert it in to DateTime in controller menthod PaidSalary Commented Nov 3, 2018 at 6:25
  • Please see: stackoverflow.com/questions/42408150/… Commented Nov 3, 2018 at 6:29
  • could u plz add your view? Commented Nov 3, 2018 at 9:08
  • You have to pass all the parameters that the method is expecting or it won't resolve the method signature to the correct method. Commented Nov 3, 2018 at 9:58

1 Answer 1

0

Below code could help you to fix your problem.

<script>
$(document).ready(function () {
    $('#PaidMonth').on('change', function () {
        var deviceid = $('#PaidMonth').val();
        alert(deviceid);
        $.ajax({
            type: 'GET',
            data: JSON.stringify({ id: 121, EmpName: "Emp_Name", PaidMonth: deviceid}),
            url: 'http://localhost:8089/HRM/PaidSalary',
            dataType: 'json',
            success: function (data) {
                console.log(JSON.stringify(data))
                vehicle = $("#MonthOfSalary").val();
                console.log(vehicle);
            },
            async: true // make it true if you want to make an async call.
        });
    });
});

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.