简体   繁体   English

在两个“模型”页面或“剃刀”页面之间传递ID

[英]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 我是Core和razor编程的新手,在我的项目中,我必须向_Context添加一个用户,然后传递添加的我们的ID

_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 当我测试代码时,我可以正确看到ID,但是它没有传递给另一页

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

and the id is null. 并且id为null。 I tried the asp-route-id="Model.Id" on the user page, but it is not working. 我在用户页面上尝试了asp-route-id =“ Model.Id”,但是它不起作用。

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

Can anyone help me with this ? 谁能帮我这个 ?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM