title: AJAX - posting JSON to controller ASP.NET MVC
body: <p>I'm attempting to make a call to the deprecated Google Finance API (just to learn) parsing the response and post it to my controller. I show the user a view with 0 values but once the response returns, I will display the parsed results.</p>
  
  <p>The results look perfect except that the view is printed to the console instead of being displayed. What am I overlooking here? Any other feedback is also welcome as I'm just trying to learn ASP.NET MVC.</p>
  
  <p>Here is my code:</p>
  
  <p>HomeController:</p>
  
  <pre><code>    public ActionResult Index3()
      {
          var model = from a in realList orderby a.Symbol select a;
  
          return View(model);
      }
  
      [HttpPost]
      public ActionResult Index3(string JSON)
      {
          // parse response...
          // listOfStocks.Add(...);
  
          var model = from a in listOfStocks orderby a.Symbol select a;
  
          return View(model);
      }
  
      static List&lt;Stocks&gt; listOfStocks = new List&lt;Stocks&gt;();
  </code></pre>
  
  <p>Index3:</p>
  
  <pre><code>@model IEnumerable&lt;WebApplication2.Models.Stocks&gt;
  
  @{
      ViewBag.Title = "Stock Texter";
  }
  &lt;h2&gt;Stock List&lt;/h2&gt;
  
  
  &lt;table class="table table-striped"&gt;
      &lt;tr&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.Symbol)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.Price)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.Change)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.ChangePercent)
          &lt;/th&gt;
          &lt;th&gt;
              @Html.DisplayNameFor(model =&gt; model.PreviousClose)
          &lt;/th&gt;
          &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
  
      @foreach (var item in Model) {
          &lt;tr&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Symbol)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Price)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Change)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.ChangePercent)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.PreviousClose)
              &lt;/td&gt;
          &lt;/tr&gt;
      }
  &lt;/table&gt;
  
  
  @section JavaScript
  {
      &lt;script src="@Url.Content("/Scripts/test.js")"&gt;&lt;/script&gt;
  }
  </code></pre>
  
  <p>test.js:</p>
  
  <pre><code>(function ($, window, document) {
      var data = "";
      $.when(
          $.getJSON("http://finance.google.com/finance/info?client=ig&amp;q=NASDAQ%3AAAPL,JPM,CAT,MSFT&amp;callback=?", function (response) {
              data = response;
              console.log("call succcessful");
          })
      ).then(function () {
          $.ajax({
              type: "POST",
              url: "/home/index3",
              data: { 'JSON': JSON.stringify(data) },
              success: function (response2) {
                  console.log(response2);
              }
          });
      });
  }(window.jQuery, window, document));
  </code></pre>