Add mechanism for interactively-rendered form to submit as HTTP request to SSR endpoint
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Is your feature request related to a problem? Please describe the problem.
I need to work with page in interactive mode, and after that submit to handle it with access to HttpContext.
I expect that model will be filled by `[SupplyParameterFromForm] RegisterInputModel Model`
after i submit form with javascript interop and invoke a function `submit()`.
But in Server interactive mode the hidden value `` is removed.
My temporary working soution is:
```cs
@if(HttpContext == null)
{
}
@* form code and markup *@
@code {
[CascadingParameter]
private HttpContext? HttpContext { get; set; }
[SupplyParameterFromForm]
private LoginInputModel Input { get; set; } = new();
[SupplyParameterFromQuery]
private string? ReturnUrl { get; set; }
protected override async Task OnInitializedAsync()
{
if (HttpContext != null && HttpMethods.IsGet(HttpContext.Request.Method))
{
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);
}
}
public async Task LoginUser()
{
if(HttpContext == null)
{
// interactive logic
var ref1 = await Js.InvokeAsync("document.getElementById", "login-form");
await ref1.InvokeVoidAsync("parentNode.submit");
return;
}
// server submit logic
var result = await SignInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);
if (result.Succeeded)
{
Logger.LogInformation("User logged in.");
RedirectManager.RedirectTo(ReturnUrl);
}
else if (result.RequiresTwoFactor)
{
RedirectManager.RedirectTo(
"Account/LoginWith2fa",
new() { ["returnUrl"] = ReturnUrl, ["rememberMe"] = Input.RememberMe });
}
else if (result.IsLockedOut)
{
Logger.LogWarning("User account locked out.");
RedirectManager.RedirectTo("Account/Lockout");
}else
{
AppStore.State.NotAuthorizedModel = new () { Message = "Other error" };
}
}
}
```
### Describe the solution you'd like
solution 1: Do not remove hidden field `_handler` with `FormName` value and in interactive mode.
solution 2: Provide some API in `EditContext` to call submit with reload page.
### Additional context
Sorry for my English...
Contributor guide
Assessment
This issue has not been assessed yet.