Closed SteveSandersonMS closed 1 year ago
<form>
with @formname
and [SupplyParameterFromForm]
: https://github.com/dotnet/aspnetcore/blob/main/src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/Forms/PlainForm.razor<EditForm>
with FormName
and [SupplyParameterFromForm]
: https://github.com/dotnet/aspnetcore/blob/main/src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/Forms/DefaultFormBoundParameter.razorFormMappingScope
: https://github.com/dotnet/aspnetcore/blob/main/src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/Forms/NestedNamedFormBoundParameter.razorThe other APIs are for layering (to allow M.A.C.Endpoints
to supply form data from HttpContext
, etc.), and to let the M.A.C.Forms
components (e.g., InputBase
and EditForm
) to interact with mapping and any mapping errors it produces. We don't expect application code to use these APIs directly, though they could if they were implementing a custom hosting model or a custom form concept.
API Review Notes:
SupplyParameterFromFormAttribute.Handler
to FormName
so it's more consistent with the component attribute.FormMappingScope.Name
be required?
FormMappingScope.Name
be called FormNamePrefix
or something?
FormValueMappingContext
and make its ctor internal.API approved!
❓ for documentation ...
Is FormName required? Yes for SSR even if there is only one form or else the experience would be really bad when additional forms are added.
... but at least for Pre7 it doesn't seem to be required in the single form case.
Is this going to throw in the future? I wasn't placing it on the single-form examples, but it sounds like you want every doc example to show setting it, even in the single-form case.
It will be required on all forms that are submitted via SSR. That is:
MapRazorComponents
endpoint as a traditional HTTP POST request, i.e., an SSR form post. We don't throw at the point of rendering a form, but only at the point that an HTTP POST arrives and doesn't specify a form name.In this SSR-form-post case, it is required on all such form posts that arrive, because otherwise when the POST request arrives we wouldn't know which form it's meant to be dispatched to. The "single form with no name" case would be dangerous and confusing because even if your app works with a single form today, someone might later add a 2nd form with no name somewhere else in the UI, and then the 1st form would become broken because now you have two forms with no name and we don't know which one to dispatch to.
Does that make sense?
API review updates implemented in https://github.com/dotnet/aspnetcore/pull/50181/commits
Background and Motivation
These are APIs related to form handling with Blazor SSR. Ultimately it's all about making
<form @onsubmit=...>
and<EditForm>
able to trigger actions on the server via an HTTP POST, map the incoming data via[SupplyParameterFromForm]
properties on components, show up any mapping errors as validation errors, and preserve attempted values even if they are unparseable.Proposed API