How do I define a method in Razor?
Razor is just a templating engine.
You should create a regular class.
If you want to make a method inside of a Razor page, put them in an @functions block.