dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.49k stars 10.04k forks source link

Can I add `TempData` to Blazor? #58779

Closed jonashendrickx closed 1 week ago

jonashendrickx commented 1 week ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

Can I add TempData support to Blazor? This was possibly a nice feature I actually likes in ASP.NET MVC in Razor Pages. But is no longer supported in Blazor. Can I have permission to open a pull request for this?

Or we we have an alternative solution that would allow something similar?

Describe the solution you'd like

[RequirePermission(Permission.Provider_ResendEmailInvite)]
    public async Task<IActionResult> ResendInvite(Guid ownerId, Guid providerId)
    {
        await _providerService.ResendProviderSetupInviteEmailAsync(providerId, ownerId);
        TempData["InviteResentTo"] = ownerId;
        return RedirectToAction("Edit", new { id = providerId });
    }

Just imagine we could be setting the TempData in the form submission handler in Blazor, and then load the value again during initialization lifecycle of the component.

It is useful if you want to pass certain values to another page, although I admit the example above might be bad, as you might as well pass it as a request parameter, but you would still risk tampering with the values. TempData appears to be safer.

Additional context

https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.ViewFeatures/src/CookieTempDataProvider.cs#L17

javiercn commented 1 week ago

Dupe of https://github.com/dotnet/aspnetcore/issues/49683