skip to Main Content

I am trying to navigate from the main Menu Index to my CreateJob file:

enter image description here

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


  1. Try:

    <li><a href="../Jobs/CreateJob?handler=UserId&id=test">Job anlegen3</a></li>
    

    result:

    enter image description here

    Login or Signup to reply.
  2. This anchor tag helper format enters the OnGetUserId handler:

    <a asp-page="/Jobs/CreateJob"
       asp-page-handler="UserId"
       asp-route-id="test">Job anlegen</a>
    

    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 the href attribute value):

    <a href="/Jobs/CreateJob?id=test&handler=UserId">Job anlegen</a>
    

    For future reference, the note just above the asp-page-handler attribute heading identifies the outcome you describe: "navigation leads to page self"

    If the referenced page doesn’t exist, a link to the current page is generated using an ambient value from the request. No warning is indicated, except at the debug log level.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search