I'd like to call the method "EditProject" of my controller "Project" with a parameter being the Id of the project.
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
Here is the code I've tried before figuring out it doesn't work :
$('.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;
});
I've also tried simply using
$.get("/Project/EditProject/" +id);
window.location.href = '@Url.Action("EditProject", "Project")' + '/' + id;
window.location.href = ("/Project/EditProject/" +id);
but it returns a 404 error.
The method called is very simple :
[HttpGet]
[Authorize(Roles = "Professional")]
public async Task<IActionResult> EditProject(int id)
{
Project p = await _unitOfWork.Projects.GetById(id);
ViewData["Title"] = "Modification du challenge " + p.ProjectName;
return View(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.
$.get("/Project/EditProject/ +id");did you mean$.get("/Project/EditProject/" +id);window.location.href = "/Project/EditProject/" + id;