{"id":13805252,"url":"https://github.com/kapi2289/InertiaCore","last_synced_at":"2025-05-13T19:30:31.433Z","repository":{"id":64933520,"uuid":"579725310","full_name":"kapi2289/InertiaCore","owner":"kapi2289","description":"Inertia.js ASP.NET Adapter.","archived":false,"fork":false,"pushed_at":"2025-02-23T21:43:53.000Z","size":67,"stargazers_count":107,"open_issues_count":8,"forks_count":22,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-23T16:37:47.540Z","etag":null,"topics":["aspnet","aspnetcore","inertia","inertiajs"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kapi2289.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-18T17:40:03.000Z","updated_at":"2025-04-16T21:19:29.000Z","dependencies_parsed_at":"2023-02-19T00:05:16.402Z","dependency_job_id":"9d071be5-c8cf-4093-a2ef-bc9dfbbc976c","html_url":"https://github.com/kapi2289/InertiaCore","commit_stats":{"total_commits":27,"total_committers":2,"mean_commits":13.5,"dds":0.07407407407407407,"last_synced_commit":"b38af98120a25133a657cc98f54b8b397c4f138a"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kapi2289%2FInertiaCore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kapi2289%2FInertiaCore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kapi2289%2FInertiaCore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kapi2289%2FInertiaCore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kapi2289","download_url":"https://codeload.github.com/kapi2289/InertiaCore/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254012923,"owners_count":21999334,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aspnet","aspnetcore","inertia","inertiajs"],"created_at":"2024-08-04T01:00:59.136Z","updated_at":"2025-05-13T19:30:31.418Z","avatar_url":"https://github.com/kapi2289.png","language":"C#","funding_links":[],"categories":["Adapters"],"sub_categories":["Server-side"],"readme":"# Inertia.js ASP.NET Adapter\n\n[![NuGet](https://img.shields.io/nuget/v/AspNetCore.InertiaCore?style=flat-square\u0026color=blue)](https://www.nuget.org/packages/AspNetCore.InertiaCore)\n[![Build](https://img.shields.io/github/actions/workflow/status/kapi2289/InertiaCore/dotnet.yml?style=flat-square)](https://github.com/kapi2289/InertiaCore/actions)\n[![NuGet](https://img.shields.io/nuget/dt/AspNetCore.InertiaCore?style=flat-square)](https://www.nuget.org/packages/AspNetCore.InertiaCore)\n[![License](https://img.shields.io/github/license/kapi2289/InertiaCore?style=flat-square)](https://github.com/kapi2289/InertiaCore/blob/main/LICENSE)\n\n## Features\n\n- [x] Validation error handling.\n- [x] Shared data.\n- [x] Partial and async lazy props.\n- [x] Server-side rendering.\n- [x] Vite helper.\n- [x] Cycle-safe model with relations data serialization.\n- [x] Properly working **PATCH**, **PUT** and **DELETE** redirections.\n\n## Table of contents\n\n- [Examples](#examples)\n- [Installation](#installation)\n- [Getting started](#getting-started)\n- [Usage](#usage)\n  * [Frontend](#frontend)\n  * [Backend](#backend)\n- [Features](#features)\n  * [Shared data](#shared-data)\n  * [Async Lazy Props](#async-lazy-props)\n  * [Server-side rendering](#server-side-rendering)\n  * [Vite helper](#vite-helper)\n    - [Examples](#examples-1)\n\n## Examples\n\nYou can check out these examples to have some starting point for your new application.\n\n- **Vue** - [NejcBW/InertiaCoreVueTemplate](https://github.com/NejcBW/InertiaCoreVueTemplate)\n- **React** - [nicksoftware/React-AspnetCore-inertiaJS](https://github.com/nicksoftware/React-AspnetCore-inertiaJS)\n\n## Installation\n\n1. Using Package Manager: `PM\u003e Install-Package AspNetCore.InertiaCore`\n2. Using .NET CLI: `dotnet add package AspNetCore.InertiaCore`\n\n## Getting started\n\nYou need to add few lines to the `Program.cs` or `Starup.cs` file.\n\n```csharp\nusing InertiaCore.Extensions;\n\n[...]\n\nbuilder.Services.AddInertia();\n\n[...]\n\napp.UseInertia();\n```\n\n## Usage\n\n### Frontend\n\nCreate a file `/Views/App.cshtml`.\n\n```html\n@using InertiaCore\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n    \u003cmeta charset=\"utf-8\"/\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/\u003e\n    \u003ctitle inertia\u003eMy App\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n@await Inertia.Html(Model)\n\n\u003cscript src=\"/js/app.js\"\u003e\u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nYou can change the root view file using:\n\n```csharp\nbuilder.Services.AddInertia(options =\u003e\n{\n    options.RootView = \"~/Views/Main.cshtml\";\n});\n```\n\n### Backend\n\nTo pass data to a page component, use `Inertia.Render()`.\n\n```csharp\n    public async Task\u003cIActionResult\u003e Index()\n    {\n        var posts = await _context.Posts.ToListAsync();\n        \n        var data = new\n        {\n            Posts = posts,\n        };\n        \n        return Inertia.Render(\"Posts\", data);\n    }\n```\n\nTo make a form endpoint, remember to add `[FromBody]` to your model parameter, because the request data is passed using\nJSON.\n\n```csharp\n    [HttpPost]\n    public async Task\u003cIActionResult\u003e Create([FromBody] Post post)\n    {\n        if (!ModelState.IsValid)\n        {\n            // The validation errors are passed automatically.\n            return await Index();\n        }\n        \n        _context.Add(post);\n        await _context.SaveChangesAsync();\n        \n        return RedirectToAction(\"Index\");\n    }\n```\n\n## Features\n\n### Shared data\n\nYou can add some shared data to your views using for example middlewares:\n\n```csharp\nusing InertiaCore;\n\n[...]\n\napp.Use(async (context, next) =\u003e\n{\n    var userId = context.Session.GetInt32(\"userId\");\n    \n    Inertia.Share(\"auth\", new\n    {\n        UserId = userId\n    });\n    \n    // Or\n    \n    Inertia.Share(new Dictionary\u003cstring, object?\u003e\n    {\n        [\"auth\"] =\u003e new\n        {\n            UserId = userId\n        }\n    });\n});\n```\n\n### Async Lazy Props\n\nYou can use async lazy props to load data asynchronously in your components. This is useful for loading data that is not needed for the initial render of the page.\n```csharp\n\n// simply use the LazyProps the same way you normally would, except pass in an async function\n\n    public async Task\u003cIActionResult\u003e Index()\n    {\n        var posts = new LazyProp(async () =\u003e await _context.Posts.ToListAsync());\n        \n        var data = new\n        {\n            Posts = posts,\n        };\n        \n        return Inertia.Render(\"Posts\", data);\n    }\n\n\n```\n\n### Server-side rendering\n\nIf you want to enable SSR in your Inertia app, remember to add `Inertia.Head()` to your layout:\n\n```html\n@using InertiaCore\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n    \u003cmeta charset=\"utf-8\"/\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/\u003e\n    \u003ctitle inertia\u003eMy App\u003c/title\u003e\n    \n    @await Inertia.Head(Model)\n\u003c/head\u003e\n\u003cbody\u003e\n@await Inertia.Html(Model)\n\n\u003cscript src=\"/js/app.js\"\u003e\u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nand enable the SSR option:\n\n```csharp\nbuilder.Services.AddInertia(options =\u003e\n{\n    options.SsrEnabled = true;\n    \n    // You can optionally set a different URL than the default.\n    options.SsrUrl = \"http://127.0.0.1:13714/render\"; // default\n});\n```\n\n### Vite Helper\n\nA Vite helper class is available to automatically load your generated styles or scripts by simply using the `@Vite.Input(\"src/main.tsx\")` helper. You can also enable HMR when using React by using the `@Vite.ReactRefresh()` helper. This pairs well with the `laravel-vite-plugin` npm package.\n\nTo get started with the Vite Helper, you will need to add one more line to the `Program.cs` or `Starup.cs` file.\n\n```csharp\nusing InertiaCore.Extensions;\n\n[...]\n\nbuilder.Services.AddViteHelper();\n\n// Or with options (default values shown)\n\nbuilder.Services.AddViteHelper(options =\u003e\n{\n    options.PublicDirectory = \"wwwroot\";\n    options.BuildDirectory = \"build\";\n    options.HotFile = \"hot\";\n    options.ManifestFilename = \"manifest.json\";\n});\n```\n\n\n#### Examples\n---\n\nHere's an example for a TypeScript React app with HMR:\n\n```html\n@using InertiaCore\n@using InertiaCore.Utils\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"utf-8\" /\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /\u003e\n    \u003ctitle inertia\u003eMy App\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    @* This has to go first, otherwise preamble error *@\n    @Vite.ReactRefresh()\n    @await Inertia.Html(Model)\n    @Vite.Input(\"src/main.tsx\")\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nwith the corresponding `vite.config.js`, which is recommended to create in the `ClientApp` directory:\n\n```js\nimport { defineConfig } from \"vite\";\nimport react from \"@vitejs/plugin-react\";\nimport laravel from \"laravel-vite-plugin\";\n\n// https://vitejs.dev/config/\nexport default defineConfig({\n  plugins: [\n    laravel({\n      input: [\"src/main.tsx\"],\n      publicDirectory: \"../wwwroot/\",\n    }),\n    react(),\n  ],\n  build: {\n    emptyOutDir: true,\n  },\n});\n```\n\n---\n\nHere's an example for a TypeScript Vue app with Hot Reload:\n\n```html\n@using InertiaCore\n@using InertiaCore.Utils\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"utf-8\" /\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /\u003e\n    \u003ctitle inertia\u003eMy App\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    @await Inertia.Html(Model)\n    @Vite.Input(\"src/app.ts\")\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nwith the corresponding `vite.config.js`, which is recommended to create in the `ClientApp` directory:\n\n```js\nimport {defineConfig} from 'vite';\nimport vue from '@vitejs/plugin-vue';\nimport laravel from \"laravel-vite-plugin\";\n\nexport default defineConfig({\n  plugins: [\n    laravel({\n      input: [\"src/app.ts\"],\n      publicDirectory: \"../wwwroot/\",\n      refresh: true,\n    }),\n    vue({\n      template: {\n        transformAssetUrls: {\n          base: null,\n          includeAbsolute: false,\n        },\n      },\n    }),\n  ],\n  build: {\n    emptyOutDir: true,\n  },\n});\n```\n\n---\n\nHere's an example that just produces a single CSS file:\n\n```html\n@using InertiaCore\n@using InertiaCore.Utils\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"utf-8\" /\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    @await Inertia.Html(Model)\n    @Vite.Input(\"src/main.scss\")\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkapi2289%2FInertiaCore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkapi2289%2FInertiaCore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkapi2289%2FInertiaCore/lists"}