I have a razor page for editing information in which I take the ID as input in onget. On this page, I want my handler to be called if a button is clicked. To do this, I need to use @page "{handler?}" in the code. But I also need to use @page "{id}" to get the ID. How is it possible to use both on one page?
@page "{id}"
<form asp-page-handler="test" method="post">
<button >test </button>
</form>
public IActionResult OnPosttest()
{
//my code
}
public void OnGet(long id)
{
}
You do not need to add @page "{handler?}",
You just need to change OnPost t est to OnPost T est, use capitalization instead, that is the razor
page naming convention, and then the method can be called.
But I also need to use @page "{id}" to get the ID. How is it possible to use both on one page?
you can use this format
@page "{handler?}/{id?}"
to use both on one page.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.