Skip to content

Server-side Setup

The first step when installing Inertia is to configure your server-side framework. These docs are written from the perspective of InertiaCore, the ASP.NET Core adapter — AspNetCore.InertiaCore on NuGet. Examples for the Laravel adapter are included as a tab in every code block so you can follow along in either runtime.

Scaffold a new InertiaCore app

The fastest way to start a new Inertia project on ASP.NET Core is the create-inertiacore scaffolder, which wires up AspNetCore.InertiaCore, Vite, and your frontend framework of choice (Vue, React, or Svelte) in one step:

Terminal window
npm init inertiacore@latest
# or
npx create-inertiacore@latest

If you’d prefer to add InertiaCore to an existing ASP.NET Core project, follow the manual steps below.

Install Dependencies

Install the InertiaCore server-side adapter. The Vite helper is optional but recommended — it auto-wires Inertia.Version(Vite.GetManifestHash) so cached assets get invalidated automatically.

Terminal window
dotnet add package AspNetCore.InertiaCore

Root Template

Next, set up the root template that will be loaded on the first page visit. This template loads your site assets (CSS and JavaScript) and contains the root <div> in which your JavaScript application will boot. InertiaCore renders it via @await Inertia.Html(Model) and optionally @await Inertia.Head(Model) for SSR head fallback content.

@using InertiaCore
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
@Vite.Input("src/app.tsx")
@await Inertia.Head(Model)
</head>
<body>
@await Inertia.Html(Model)
</body>
</html>

By default, InertiaCore looks for a root view at ~/Views/App.cshtml. You can change the root view path via builder.Services.AddInertia(options => options.RootView = "~/Views/Layouts/Inertia.cshtml");.

Register InertiaCore

Register InertiaCore in Program.cs with AddInertia() and insert the middleware into the request pipeline with UseInertia(). No CLI publish step is required — the middleware is shipped inside the NuGet package.

Program.cs
using InertiaCore.Extensions;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
builder.Services.AddInertia();
builder.Services.AddViteHelper();
var app = builder.Build();
app.UseStaticFiles();
app.UseInertia();
app.MapControllers();
app.Run();

UseInertia() registers the InertiaCore middleware, which handles protocol headers, partial reloads, validation-error forwarding, and asset versioning. Use Inertia.Version(...) to set your asset version and Inertia.Share(...) to define shared data.

Creating Responses

That’s it, you’re all ready to go server-side! Return an Inertia response from a controller with Inertia.Render("Component", props). The component path maps to a JavaScript page under your frontend source tree.

using InertiaCore;
public class EventsController : Controller
{
private readonly AppDbContext _context;
public EventsController(AppDbContext context) => _context = context;
[HttpGet("/events/{id:int}")]
public IActionResult Show(int id)
{
var evt = _context.Events.Find(id);
return Inertia.Render("Event/Show", new
{
Event = new
{
evt.Id,
evt.Title,
evt.StartDate,
evt.Description,
},
});
}
}