---
title: "Post JavaScript array with AJAX to asp.net MVC controller"  
description: "Post JavaScript array with AJAX to asp.net MVC controller"  
author: "Manoj Bhatt"  
published: 2013-04-03  
updated: 2013-04-03  
canonical: https://www.mindstick.com/forum/700/post-javascript-array-with-ajax-to-asp-dot-net-mvc-controller  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 2 minutes  

---

# Post JavaScript array with AJAX to asp.net MVC controller

Hi Everyone!\
**My [controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc):**\

```
[HttpPost]public ActionResult AddUsers(int projectId, int[] useraccountIds){    ...}
```

I'd like to [post](https://www.mindstick.com/articles/12829/aspects-that-make-australia-post-shipping-extension-a-useful-tool) the [parameters](https://www.mindstick.com/articles/87/passing-parameters-in-c-sharp) to the controller via AJAX. Passing the int projectId isn't a [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic), but I can't manage to post the int[].\
**My JS [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):**\

```
function sendForm(projectId, target) {    $.ajax({        traditional: true,        url: target,        type: "POST",        data: { projectId: projectId, useraccountIds: new Array(1, 2, 3) },        success: ajaxOnSuccess,        error: function (jqXHR, exception) {            alert('Error message.');        }    });}
```

I tried it with a test [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) but no success. :( I also tried to set traditional: true, or contentType: '[application](https://www.mindstick.com/articles/12824/calculator-application-in-android)/[json](https://www.mindstick.com/forum/34446/convert-json-string-to-object); charset=utf-8' but no [success as](https://answers.mindstick.com/qa/50180/in-what-ways-did-the-goat-contribute-to-the-us-expansion-and-success-as-a-world-power) \
well ...\
The int[] useraccountIds posted to my controller is always null.

## Replies

### Reply by AVADHESH PATEL

Hi Manoj!\
Try this way\

```
$.ajax({        traditional: true,        url: target,        type: "POST",        data: { projectId: projectId, useraccountIds: JSON.stringify(new Array(1, 2, 3)) },        success: ajaxOnSuccess,        error: function (jqXHR, exception) {            alert('Error message.');        }    });
```


---

Original Source: https://www.mindstick.com/forum/700/post-javascript-array-with-ajax-to-asp-dot-net-mvc-controller

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
