I’m trying to call a Razor Pages method from ajax but it ends up just calling the OnGet() method of the page. The url seems right as it’s
https://localhost:7100/?handler=SearchCityState&cityTerm=Det
The method I want to call is in the Index.cshtml.cs file and the name is correct. It’s defined as:
public async Task<IActionResult> SearchCityState(string cityTerm){
...
}
If I put that url in the browser it goes to my OnGet() method instead. Am I missing some configuration or something?
>Solution :
You need to prefix handler names with OnGet or OnPost, otherwise they are just any method as far as Razor Pages is concerned:
public async Task<IActionResult> OnGetSearchCityState(string cityTerm){
...
}