I have searched all over for an answer to this question, All I can find is information relating to ASP.Net MVC. I am using Razor pages, and have found most of the answers to be either useless or relying on MVC specific actions that I don't understand and know how to use.
What I want to do, if possible, is render a razor page, with its view model, to an HTML string that I can then send as the body of an email message, or I guess use for other things as I need it later.
I'm having trouble with the solutions I have found actually properly passing model data to the view, so when it encounters references to model objects in the view it returns an error "not set to an instance of an object". I can load the page otherwise with no trouble.
The page in question requires passing route data to fetch the needed info from a database, the onget method runs some methods to retrieve and calculate some things, and so on.
I feel like this must be an easy question, but like I said I just can't find any relevant info. In short, I want to pass a command from one page to render a different page, with input from its viewmodel, into the output HTML that I can send via email.
Edit for clarity:
What I'm trying to do, I have an accounting program I am building. It has the ability to generate invoices based on a complex model of several different database objects. (because it's not a simple invoice program) I have the invoice displayed as a razor view, with a PageModel governing behavior that runs a few methods, fetches data from several different sources. Because of the architecture of the program, the invoice is generated on demand, can have payments added, etc.
The invoice is displayed on one page wrapped inside the layout, and a different version of the invoice displayed layout-free for the purpose of printing.
I want to take this second invoice, the page and the code that already exists, fetch it from within a method called in a different page, compile the razor syntax with method from the PageModel to Html, and send that Html as the body of an email. Basically, do what ASP.Net does when you load the page, but instead of sending the Html to the browser, send it to the method and store it as a string.
The problem I'm running into is that none of the solutions I'm finding are capable of doing this -they can run simple tasks, but aren't made to do anything to the extent of what I want.
Right now the program just sends a link to invoice at the hosted URL. That's a fine enough solution, but I'd really like to be able to extract it from the program entirely.
If I can't do this the way I'd like there are other solutions. But it would be very nice to be able to use the nicely styled and designed page I already have.