title: jQuery Ajax returns undefined result from asp.net core controller's POST action
body: <p>Can't make friends out of my AJAX and MVC 6 controller.</p>
  
  <p>This is how I define AJAX call for <em>SetFormValues</em> POST-action:</p>
  
  <p><strong>Index.cshtml</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>$.ajax({
      type: "Post",
      url: "Home/SetFormValues",
      data: { Name: name, Phone: phone },
      dataType: "json",
      success: function (result) {
          SuccessFunction(result)
      },
      error: function () {
          alert("ALARM!");
      },
      async: false
  })
  </code></pre>
  
  <p>I see that the controller works and executes <em>SetFormValues</em> action which is defined as the following:</p>
  
  <p><strong>HomeController.cs</strong></p>
  
  <pre class="lang-cs prettyprint-override"><code>[HttpPost]
  public JsonResult SetFormValues(string Name, string Phone)
  {
      string NameErrorStr = string.IsNullOrWhiteSpace(Name) ? "Обязательное поле" : string.Empty;
      string PhoneErrorStr = string.IsNullOrWhiteSpace(Phone) ? "Обязательное поле" : string.Empty;
  
      var result = new { NameError = NameErrorStr, PhoneError = PhoneErrorStr };
      var jresult = Json(result);
  
      return jresult;
  }
  </code></pre>
  
  <p>Debugger shows that action executes and my resulting JSON object fills correctly:
  <a href="https://i.stack.imgur.com/HLDIC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HLDIC.jpg" alt="Debugger enters SetFormValues action correctly"></a></p>
  
  <p>Finally, his is how <em>SuccessFunction(result)</em> is defined:</p>
  
  <p><strong>Index.cshtml again</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>function SuccessFunction(result) {
      alert("Success function shit executed. result=" +
          result + "NameError=" +
          result.NameError + ". PhoneError=" +
          result.PhoneError);
  
      $("#nameerror").append(result.NameError);
      $("#phoneerror").append(result.PhoneError);
  }
  </code></pre>
  
  <p>Function works, alert is raised but result stay 'undefined' no matter what I do:
  <a href="https://i.stack.imgur.com/vaxdC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vaxdC.jpg" alt="enter image description here"></a></p>
  
  <pre><code>result = [object Object]
  result.val = undefined
  </code></pre>
  
  <p>Maybe I have to deserialize JSON result properly or fill some properties in it's declaration above, I don't know.
  I'm using the lattest libraries for jquery, validate and unobtrusive.
  I also tried <em>JSON.parse(result)</em>, as it mentioned in the lattest jQuery specification, but it didn't work as well.</p>
  
  <p>Please, help me :)</p>