Skip to content

Commit

Permalink
Update README, add "Flash Messages"
Browse files Browse the repository at this point in the history
  • Loading branch information
mergehez committed Oct 6, 2024
1 parent b8b1c0c commit c3cafda
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Feel free to contribute to the project by creating issues or pull requests.
* [Backend](#backend)
- [Features](#features)
* [Shared data](#shared-data)
* [Flash Messages](#flash-messages)
* [Server-side rendering](#server-side-rendering)
* [Vite helper](#vite-helper)
- [Examples](#examples-1)
Expand Down Expand Up @@ -181,6 +182,26 @@ app.AddInertiaSharedData(httpContext => new InertiaProps
});
```

### Flash Messages

You can add flash messages to your responses using the `Inertia.Back(url).WithFlash(...)` method.

```csharp
[HttpDelete("{id:int}")]
public async Task<IActionResult> Destroy(int id)
{
/// find user
if (!user.IsAdmin)
return Inertia.Back().WithFlash("error", "Admins cannot be deleted.");

// delete user
return Inertia.Back().WithFlash("success", "User deleted.");
}
```


### Server-side rendering

If you want to enable SSR in your Inertia app, remember to add `Inertia.Head()` to your layout:
Expand Down

0 comments on commit c3cafda

Please sign in to comment.