Search code examples
asp.netasp.net-corerazor

Razorpage navigation leads to page self


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...


Solution

  • Try:

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

    result:

    enter image description here