title: ASP.Net Mvc How to pass data from View into Controller with a Button using Ajax
body: <p>I have a button that takes data from a Model and passes it into an Ajax function.
  This function should then call a controller, but it doesn't and a breakpoint on a controller is never hit.</p>
  <p>The button with parameters taken from Model (both are strings):</p>
  <pre><code>&lt;button class=&quot;btn btn-primary btn-lg active&quot; onclick=&quot;PassHwData(@obj.Name,@obj.HomeWorldBonus)&quot; &gt;Choose @obj.Name&lt;/button&gt;
  </code></pre>
  <p>the Ajax function:</p>
  <pre><code>&lt;script&gt;
            function PassHwData(name, hwBonus)
            {
                $.ajax({
                    url: '@Url.Action(&quot;Create&quot;, &quot;HomeWorld&quot;)',
                    type: &quot;POST&quot;,
                    data: {'name' : name, 'hwBonus' : hwBonus}
                    datatype: &quot;text&quot;,
                    success: function(name, hwBonus)
                    {
                        document.getElementById('success').innerHTML += success {name}{hwBonus};
                    }
                })
            }
  &lt;/script&gt;
  
  &lt;div id=success&gt;
        success: 
  &lt;/div&gt;
  </code></pre>
  <p>The Controller (there are other methods but I omitted them here):</p>
  <pre><code>using DarkHeresy.Application.Services.Interfaces;
  using Microsoft.AspNetCore.Authorization;
  using Microsoft.AspNetCore.Mvc;
  
  namespace DarkHeresy.Web.Controllers
  {
      [Authorize]
      public class HomeWorldController : Controller
      {
          private readonly IHomeWorldService _homeWorldService;
          public HomeWorldController(IHomeWorldService homeWorldService)
          {
              _homeWorldService = homeWorldService;
          }
          [HttpPost]
          public async Task&lt;IActionResult&gt; Create(string name, string hwBonus)
          {
              return View(await _homeWorldService.UpdateCharacterList()); //this will have implementation later
          }
      }
  }
  </code></pre>
  <p>I should also add that I am using Asp.Net Core MVC and going with Clean Architecture and am super new at both of those things.</p>