Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

string array values is not passing from JavaScript to controller method

I am trying to pass the values from JavaScript string array variable into controller method. The method is called but the value is not being passed. Here is my example
Controller

[HttpPost]       
public IActionResult ReinstateEmployeeUpdate(List<string> employeeIds)
{
   return View( );
}
<script type="text/javascript">
function UpdateEmployee() {
        var employeeIds = [];         
        var employeeIds = ["346", "347"];
         
        $.ajax({
            type: "POST",
            contentType: "application/json",
            headers: { 'Content-Type': 'application/json' },
            url: "/Employee/ReinstateEmployeeUpdate",
            dataType: "json",
            data: JSON.stringify(employeeIds),
            success: function (response) {
                console.log(response);
            },

            error: function (response) {
                console.log(response.responseText);
            }
        });
    }
</script>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You could try as below:

[HttpPost]       
    public IActionResult ReinstateEmployeeUpdate([FromBody]List<string> employeeIds)
    {
       return View( );
    }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading