title: Using a list of Json results as parameters for a mvc actionresult, to return objects from database with Linq and Lambda
body: <p>There is an <code>Api</code> method called via <code>Ajax</code>. After parsing and other necessary things has been finished, I get the following result.</p>
  
  <pre><code>["IG4","E1 ","E16"]
  </code></pre>
  
  <p>As soon as the results received, it calls another <code>MVC ActionResult</code> to display data from the database, where the postcode attribute of the object contains one of these <code>Json</code> results. However it does not work.</p>
  
  <pre><code>public ActionResult SearchResult(JsonResult postcode)
      {
          var posts = db.Posts.Where(p =&gt; p.PostCode.Contains(postcode));
          return PartialView("postlist", posts);
  
      }
  </code></pre>
  
  <p>When the <code>ActionResult</code> is called via <code>Ajax</code>, I checked what <code>url</code> is being called and got the following result</p>
  
  <pre><code>SearchResult?postcode%5B%5D=IG4&amp;postcode%5B%5D=E1+&amp;postcode%5B%5D=E16
  
  
  $('#searchBtn').on('click', function () {
          var _postcode = $('#searchPostcode').val();
          var _distance = $('#searchDistance').val();
          alert("postcode " + _postcode + " distance " + _distance);
          var _url = '@Url.Action("GetPostcodesWithin", "Api/PostcodeApi")';  // don't hard code url's
          $.ajax({
              type: "GET",
              url: _url,
              data: { postcode: _postcode, distance: _distance },
              success: function(data) {                    
                  alert("search ok");
  
                  $.ajax({
                      type: "GET",
                      url: '@Url.Action("SearchResult", "Posts")',
                      data: { postcode: data },
                      success: function (data) {
                          alert("Post results called");
                          $("#postList").html(data).show();
                      },
                      error: function (reponse) {
                          alert("error : " + reponse);
                      }
                  });
              },
              error: function (reponse) {
                  alert("error : " + reponse);
              }
          });
      });
  </code></pre>
  
  <p><code>Json</code> data returned from <code>GetPostcodesWithin</code> method is displayed on the top, which is passed onto <code>SearchResult</code></p>