Skip to content

Conversation

@adrum
Copy link
Contributor

@adrum adrum commented Sep 20, 2025

Recrated #36 due to not being based on v1:

This will be used when working on empty responses in #28

Also, much of the time, I like to be able simply redirect back to the request came from on POST requests. This allows for something like:

using InertiaCore;
using Microsoft.AspNetCore.Mvc;

namespace TestCsrf.Controllers;

public class FormController : Controller
{
    public IActionResult Index()
    {
        var props = new
        {
            Success = TempData["SuccessMessage"] != null,
            Message = TempData["SuccessMessage"]?.ToString()
        };

        return Inertia.Render("Form", props);
    }

    [HttpPost]
    public IActionResult Submit([FromForm] SubmitFormRequest request)
    {
        if (!ModelState.IsValid)
        {
            return Inertia.Back();
        }

        // Process the form data
        TempData["SuccessMessage"] = $"Form submitted successfully! Name: {request.Name}, Email: {request.Email}";

        return Inertia.Back();
    }
}

public class SubmitFormRequest
{
    public string Name { get; set; } = string.Empty;
    public string Email { get; set; } = string.Empty;
    public string Message { get; set; } = string.Empty;
}

@adrum adrum changed the base branch from main to v1 September 20, 2025 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant