Doaa Radwan
Doaa Radwan

Reputation: 77

Passing ID between two Model or Razor Pages

I am new to Core and razor programming and in my project I have to add a user to the _Context then pass the ID of the added us

_Context.StaffMember.Add(StaffMember);
            await _Context.SaveChangesAsync();

            Id = StaffMember.UserId;
            return RedirectToPage("./Invite", Id);

When I tested the code, I can see the ID correctly, but it is not getting passed to the other page

public async Task<IActionResult> OnGetAsync(int? id){}

and the id is null. I tried the asp-route-id="Model.Id" on the user page, but it is not working.

<input type="submit" value="Add" class="btn btn-primary" asp-route-id="Model.Id"/>

Can anyone help me with this ?

Upvotes: 3

Views: 1061

Answers (1)

Edward
Edward

Reputation: 29996

Solution

return RedirectToPage("./Invite", new { id = Id})

Upvotes: 4

Related Questions