ant-design-blazor / ant-design-blazor

🌈A rich set of enterprise-class UI components based on Ant Design and Blazor.
https://antblazor.com/
MIT License
5.79k stars 1.06k forks source link

.NET 8 using Form of AntDesign with error FormName parameter if using <EditForm> #3453

Closed nguyendkn closed 2 months ago

nguyendkn commented 1 year ago

The POST request does not specify which form is being submitted. To fix this, ensure

elements have a @formname attribute with any unique value, or pass a FormName parameter if using .

Screenshot 2023-10-07 at 00 36 13 Screenshot 2023-10-07 at 00 36 32 Screenshot 2023-10-07 at 00 36 50
ElderJames commented 1 year ago

Thanks for contacting us @nguyendkn . We need to add the Name property for the components. Would you please help us sending a PR for that?

stfei commented 10 months ago

我也一样的问题,而且当关闭预呈现时就不会报错 <Routes @rendermode="new InteractiveServerRenderMode(prerender: false)" />

CrosRoad95 commented 9 months ago

I have simillar issue. tried setting render mode as @stfei proposed, didn't work, can not add method="post" because:

[2024-01-03T07:30:42.129Z] Error: System.InvalidOperationException: Object of type 'AntDesign.Form`1[[ProjectName.LoginFormModel, ProjectName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' does not have a property matching the name 'method'.
   at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.ThrowForUnknownIncomingParameterName(Type targetType, String parameterName)
   at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.SetProperties(ParameterView& parameters, Object target)
   at Microsoft.AspNetCore.Components.ComponentBase.SetParametersAsync(ParameterView parameters)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView directAndCascadingParameters)

full example:

<Form Model="@Model" Name="login" method="post" // method attribute throws error
      OnFinish="OnFinish"
      OnFinishFailed="OnFinishFailed"
      LabelColSpan="8"
      WrapperColSpan="16">
    <FormItem Label="Username">
        <Input @bind-Value="@context.Username" />
    </FormItem>
    <FormItem Label="Password">
        <InputPassword @bind-Value="@context.Password" />
    </FormItem>
    <FormItem WrapperColOffset="8" WrapperColSpan="16">
        <Checkbox @bind-Value="context.RememberMe">Remember me</Checkbox>
    </FormItem>
    <FormItem WrapperColOffset="8" WrapperColSpan="16">
        <Button Type="@ButtonType.Primary" HtmlType="submit">
            Submit
        </Button>
    </FormItem>
</Form>

@code
{
    public class LoginFormModel
    {
        public string Username { get; set; }
        public string Password { get; set; }
        public bool RememberMe { get; set; }
    }

    [SupplyParameterFromForm]
    private LoginFormModel Model { get; set; } = new LoginFormModel();

    private void OnFinish(EditContext editContext)
    {
        Console.WriteLine($"Success:{JsonSerializer.Serialize(Model)}");
    }

    private void OnFinishFailed(EditContext editContext)
    {
        Console.WriteLine($"Failed:{JsonSerializer.Serialize(Model)}");
    }
}
HyokaChen commented 9 months ago

hi, is it fixed in the 0.17.2?I have simillar issue too.😂

ElderJames commented 9 months ago

Hello @HyokaChen , please use From at Interactive mode first. We will relese this feature in 0.18.0.

ElderJames commented 7 months ago

@nguyendkn We have add Method parameter in 0.18.0, but also have an issue #3709 , will be fixed in #3580 .