title: ASP.NET Core - Call controller method in javascript without Ajax
body: <p>I'd like to call the method "EditProject" of my controller "Project" with a parameter being the Id of the project.</p>
  
  <p>I've seen many people using Ajax, but the problem is I'd like to call the controller which in turn will redirect the user to the View "EditProject", I don't want to stay on the same page</p>
  
  <p>Here is the code I've tried before figuring out it doesn't work :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$('.edit-project').click(function (d) {
      var id = $(this).attr('data-projectId');
  
      $.ajax({
          url: '@Url.Action("EditProject", "Project")',
          data: { id: id },
          type: "GET"
      }).done(function() {
          console.log("Done");
      });
      return false;
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>I've also tried simply using</p>
  
  <pre><code>$.get("/Project/EditProject/" +id); 
  window.location.href = '@Url.Action("EditProject", "Project")' + '/' + id;
  window.location.href = ("/Project/EditProject/" +id);
  </code></pre>
  
  <p>but it returns a 404 error.</p>
  
  <p>The method called is very simple :</p>
  
  <pre><code>[HttpGet]
  [Authorize(Roles = "Professional")]
  public async Task&lt;IActionResult&gt; EditProject(int id)
  {
      Project p = await _unitOfWork.Projects.GetById(id);
       ViewData["Title"] = "Modification du challenge " + p.ProjectName;
       return View(p);
  }
  </code></pre>
  
  <p>And as expected with Ajax, it does return the View, but it returns it as a response to the ajax query, and thus it doesn't redirect and show the View as I would like.</p>