Passing a parameter to a page for ASP.Net Web App

From TRCCompSci - AQA Computer Science
Jump to: navigation, search

In the model for the page you should already have a `OnGet()` method. This is run when the page is loaded.

So, you need to add the `HttpGet` command below just before the `OnGet` method. You then need to add the `int id=0` to the parameters of the `OnGet` method:

[HttpGet("{id:int}")]
public void OnGet(int id=0)
{

}

You can then pass in a parameter using something like:

https://localhost:7137/mypage?id=1

Notice the `?` is used to differentiate the parameters in the url. The `id` in the url will then be passed into the `OnGet` method.