Quick Start
Add Inertia.Net to an ASP.NET Core app, create the root template and render your first page.
Already using the starter template? Its services, middleware, root template and frontend are configured for you. These steps are for adding Inertia to an existing app or building one manually.
Every app needs the same four things:
Register Inertia and the protocol middleware
Add a root template with the Inertia tokens
Render a page from an endpoint
Connect a client and run Vite
1. Register the services
Choose one backend style. All three use the same protocol middleware and the same Render(...) result.
Why AddValidation and antiforgery up front?
AddValidation() enables the Minimal API integration used by .WithInertiaValidation(). UseInertiaAntiforgery() issues the XSRF-TOKEN cookie and validates every unsafe request, so forms work from the first commit.
2. Add the root template
The root template is an HTML file in the content root. The default name is app.html.
Remove @viteReactRefresh for Vue and Svelte. @inertia is required. The other tokens are described in Pages and responses.
Make sure app.html is copied to the output and publish directory:
3. Create the page component
The page name passed to Render must match the client resolver. With @inertiajs/vite the resolver maps ClientApp/pages/** automatically.
The client entry only needs to start Inertia:
Not using @inertiajs/vite?
Pass your own resolve and setup functions to createInertiaApp. The client setup page shows both forms for React, Vue and Svelte.
4. Run it
Start Vite and ASP.NET Core in two terminals, from the project directory:
Open the URL printed by dotnet watch (not the Vite URL). The first visit to / should display “Hello from .NET”.
For production, build the client and publish the app:
Deploy wwwroot/build and app.html with the published app.