I am trying to navigate from the main Menu Index to my CreateJob file:
I am also needing to give the user Id with the link.
I tried 3 different ideas:
<li><a href="../Jobs/CreateJob?id=test">Job anlegen3</a></li>
<a asp-page="../Jobs/CreateJob?id=test">Job anlegen</a>
@Html.ActionLink("Job anlegen", "Jobs", "CreateJob", new { id = Model.userId })
The first one actually leads to the page I want but for some reason it looks like the controller behind the page seems to be disabled or not responding?
The other two just lead to the same page again and not away from it…
The last one generetaes this link:
https://localhost:44306/MainMenu?action=Jobs&controller=CreateJob
The create JOb simply does this:
public class CreateJob : PageModel
{
public string userId = string.Empty;
public async Task<IActionResult> OnGetUserId(string id)
{
// gets the url params
this.userId = id;
return Page();
}
}
But this gets ignored with the first link…
2
Answers
Try:
result:
This anchor tag helper format enters the
OnGetUserId
handler:The
asp-page-handler
attribute in the anchor tag helper is found here.The above helper format produces the anchor tag listed in @Qing’s answer (although without
..
at the start of thehref
attribute value):For future reference, the note just above the
asp-page-handler
attribute heading identifies the outcome you describe: "navigation leads to page self"