title: ASP.NET MVC Core posting just a string to controller via Ajax Post
body: <p>Trying to send a string value to Home controller using Ajax. Following Ajax call gives the error (in Google Chrome developer tool): <code>Failed to load resource: the server responded with a status of 404 (Not Found)</code>:</p>
  
  <pre><code>$.ajax({
      url: 'Home/TestAction',
      data: "Test data",
      type: 'POST',
      success: function (obj) {
          alert('Suceeded');
      }
  });
  </code></pre>
  
  <p><strong>UPDATE</strong>:</p>
  
  <p><strong>After</strong> I've tried the url part from all the responses (as of now) to this post, the url turns out to be correct but I'm still getting a <code>warning</code> and an <code>error</code> as shown in the image below. <strong>NOTE</strong>: The names of the controller and action in the image are different but they are in the same default folder called Controllers in VS2015. I've not created any subfolder etc. Also, this is on development machine <code>Win10 with VS2015 ASP.NET Core 1.1, IIS EXPRESS</code>. Please click on the image to be able to see the message in clear.</p>
  
  <p><strong>UPDATE 2</strong>:</p>
  
  <p>To make my question simpler to understand, I've created a test ASP.NET Core app following this <a href="https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/adding-model" rel="nofollow noreferrer">official ASP.NET MVC Core tutorial</a>. Please see the error image below.</p>
  
  <p><strong>Controller</strong>:</p>
  
  <pre><code>[HttpPost]
  [ValidateAntiForgeryToken]
  public async Task&lt;IActionResult&gt; Edit(int id, [Bind("ID,Genre,Price,ReleaseDate,Title")] Movie movie)
  {
      if (id != movie.ID)
      {
          return NotFound();
      }
  
      if (ModelState.IsValid)
      {
          try
          {
              _context.Update(movie);
              await _context.SaveChangesAsync();
          }
          catch (DbUpdateConcurrencyException)
          {
              if (!MovieExists(movie.ID))
              {
                  return NotFound();
              }
              else
              {
                  throw;
              }
          }
          return RedirectToAction("Index");
      }
      return View(movie);
  }
  </code></pre>
  
  <p><strong>View</strong> [..\views\movies\Index.cshtml]. NOTE: I've only added an extra button <code>&lt;button type="button" id="testid" class="Savebtn"&gt;Test&lt;/button&gt;
  </code> and the <code>Ajax</code> call at the end.</p>
  
  <pre><code>@model MovieGenreViewModel
  
  @{
      ViewData["Title"] = "Index";
  }
  
  &lt;h2&gt;Index&lt;/h2&gt;
  
  &lt;p&gt;
      &lt;a asp-action="Create"&gt;Create New&lt;/a&gt;
  &lt;/p&gt;
  &lt;form asp-controller="Movies" asp-action="Index" method="get"&gt;
      &lt;p&gt;
          &lt;select asp-for="movieGenre" asp-items="Model.genres"&gt;
              &lt;option value=""&gt;All&lt;/option&gt;
          &lt;/select&gt;
  
          Title: &lt;input type="text" name="SearchString"&gt;
          &lt;input type="submit" value="Filter" /&gt;
      &lt;/p&gt;
  &lt;/form&gt;
  &lt;table class="table"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.movies[0].Genre)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.movies[0].Price)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.movies[0].ReleaseDate)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.movies[0].Title)
              &lt;/th&gt;
              &lt;th&gt;&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
  @foreach (var item in Model.movies) {
          &lt;tr&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Genre)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Price)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.ReleaseDate)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Title)
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;button type="button" id="testid" class="Savebtn"&gt;Test&lt;/button&gt;
                  &lt;a asp-action="Edit" asp-route-id="@item.ID"&gt;Edit&lt;/a&gt; |
                  &lt;a asp-action="Details" asp-route-id="@item.ID"&gt;Details&lt;/a&gt; |
                  &lt;a asp-action="Delete" asp-route-id="@item.ID"&gt;Delete&lt;/a&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
  }
      &lt;/tbody&gt;
  &lt;/table&gt;
  @section scripts
  {
      &lt;script&gt;
          $(document).ready(function () {
  
              $('.Savebtn').click(function () {
  
                      $.ajax({
                          url: '@Url.Action("Edit", "Movies")',
                          data: "Test data",
                          type: 'POST', //POST if you want to save, GET if you want to fetch data from server
                          success: function (obj) {
                              // here comes your response after calling the server
                              alert('Suceeded');
                          },
                          error: function (obj) {
                              alert('Something happened');
                          }
                      });
              });
          });
      &lt;/script&gt;
  }
  </code></pre>
  
  <p><strong>Error [in Google Chrome developer tool]</strong>:</p>
  
  <p><a href="https://i.stack.imgur.com/RuXor.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RuXor.png" alt="enter image description here"></a></p>