title: Passing a string array to mvc controllers using ajax
body: <p>I need to pass list of strings from multiple select to the controller. Though the requirement looked very simple to me, I was breaking my head for the past hour in this. I have did a fair research on this, but unable to succeed. </p>
  
  <p>Below is my Javascript code. Please ignore the comments. I was successfully able to fetch the list of items in the multiple select. While i do the ajax call, I get the error "Object reference not set an instance of an object.</p>
  
  <pre><code>function submitForm() {
      var selected = $('#selectedTasks option').map(function(){ 
          return this.value 
      }).get()
      var postData = { selectedTasks : selected } //corrected as suggested
  
      //selectedTasks = JSON.stringify({ 'selectedTasks': selected });
      alert(postData);
  
      $.ajax({
          type: "POST",
          //contentType: 'application/json; charset=utf-8',
          url: '@Url.Action("AssignTasks", "MonthEndApp")',
          dataType: 'json',
          data: postData,
          traditional: true,
          success: function (data) {                
              alert("Success");
          },
          error: function (xhr) {                    
              alert(xhr.responseText);
          } 
      });
  }
  </code></pre>
  
  <p>MonthEndAppController.cs</p>
  
  <pre><code>[HttpPost]
  public void AssignTasks(List&lt;String&gt; selectedTasks)
  {
      //do something
  }
  </code></pre>
  
  <p>Can someone guide me where exactly I have gone wrong? Can someone suggest me what is wrong? </p>
  
  <p>EDIT : As suggested by Mr. Rory I have made the java script changes. Now the Java script part works absolutely fine. But the Controller is not getting called when the ajax request is made. Can someone help me out if something wrong in the call made to controller ? </p>