Skip to content

Responses

Creating Responses

Creating an Inertia response is simple. To get started, invoke the Inertia::render() method within your controller or route, providing both the name of the JavaScript page component that you wish to render, as well as any props (data) for the page.

In the example below, we will pass a single prop (event) which contains four attributes (id, title, start_date and description) to the Event/Show page component.

using InertiaCore;
public class EventsController : Controller
{
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,
},
});
}
}
<meta name="twitter:title" content="@Model.Props["event"].Title">
return Inertia.Render("Event", new { Event = evt })
.WithViewData(new Dictionary<string, object> { ["meta"] = evt.Meta });
<meta name="description" content="@ViewData["meta"]">