title: How to pass local storage item to MVC controller
body: <p>I am trying to pass an array of strings from my local storage (key value) to MVC controller. Here's my code:</p>
  <p>In cshtml View file:</p>
  <pre><code> &lt;script&gt;
  
          function getFavouriteBooks() {
              var ids = JSON.parse(localStorage.getItem(&quot;bookIds&quot;));
              // returns: [&quot;1&quot;, &quot;2&quot;, &quot;3&quot;]
  
              $.ajax({
                  type: &quot;POST&quot;,
                  traditional: true,
                  url: '@Url.Action(&quot;Favourites&quot;, &quot;Home&quot;)',
                  data: { ids: ids },
                  dataType: &quot;json&quot;,
                  contentType: &quot;application/json; charset=utf-8&quot;,
                  success: function (result) {
                      alert(result.Result);
                  }
              }});
          }
      &lt;/script&gt;
  
  
     &lt;button onClick=&quot;getFavouriteBooks()&quot;&gt;Display Favourites&lt;/button&gt;
  
  </code></pre>
  <p>My controller:</p>
  <pre><code>public async Task &lt; ViewResult &gt; Favourites(string ids) {
      // code that fetches book data from API 
  
      if (data != null)
  
      {
          var bookList = JsonConvert.DeserializeObject &lt; Book[] &gt; (data);
  
          foreach(var book in bookList) {
              var matches = new List &lt; bookList &gt; ();
              if (bookList.All(book =&gt; ids.Contains(book.Id))) {
                  matches.Add(book);
              }
  
              return View(&quot;Index&quot;, matches.ToArray());
          }
      }
      return View(&quot;Index&quot;);
  }
  
       
  </code></pre>
  <p>The controller action gets called successfully on the button click but the ids parameter is always null even though it isn't when in the console. Where am I going wrong?</p>