-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blazor sets EditForm Model to null in unexpected situations #51420
Comments
Thanks for contacting us. We're moving this issue to the |
This was annoying. I have had quite a lot of problems with the changing behavior of forms throughout the previews and RCs. This was the last one that I tackled. |
This is extremely annoying and still happening with .NET 8 RTM. I was able to reproduce the problem reliably using a checkbox binding:
Without the |
This issue should really be part of the 8.0.x milestone. It is extremely annoying to have dummy field in many of your forms just as a work around for this. |
Thanks for contacting us. We're moving this issue to the |
Discussed this offline. We may end up creating an analyzer to warn customers from falling into this pitfall. |
@mkArtakMSFT can you explain what the pitfall is? I am hitting this issue -- I'm editing the template-generated Register.razor page to have an additional EditForm on it with other user info (it's a separate form because I wanted to be able to reuse it as a razor component on a user edit page as well) -- but whenever I try to "submit" data to that form (it maintains a list of claims for that user), I get the error from the OP saying I need a Model parameter even though I have one. I'm super new to .NET in general and so I get the impression there's a lot of knowledge going on behind the scenes in this thread. Could you explain what is happening and why this is a pitfall and not just a bug? |
So far, this has been the most frustrating issue I've run into with Blazor SSR, and the tooling provides effectively no guidance as to what is going wrong. This is especially problematic as someone attempting to adopt the framework for the first time, since I'm naturally unsure if a problem like this is an issue in my understanding of how things are supposed to work, or an issue with my code. For me, the situation has been as follows:
The issue is resolved by adding a superfluous I expected that the logic for mapping would call the form's model's empty constructor, then map in the fields it observes in the form submission, so I didn't expect any behaviour change when adding new fields to my model. Unexpected behaviour aside, this has proven incredibly frustrating to debug. I can find no easy way to see why In general, I expected some kind of exception to be raised, or a debug message, or something inside Visual Studio to give me a hint as to why that binding failed and what I could do about it. I also expected some kind of callback I could intercept to modify (or understand) the mapping between the The issue has been significantly exacerbated by there being no samples I could find demonstrating how to handle HasMany/collection relationships in Blazor forms. |
I was just tripped up by this scenario, albeit silly, I would toss in for this issue:
You got me Blazor Team! |
Hi, To add my 2 cents, this issue is extremely frustrating, in the scenario of using checkbox, the default behavior is : to do not send value if the checkbox is not checked (the value being 'False'). Currently I'm having a bunch of if statements below every checkbox :
On every field I'm adding these hidden field, as pointed by @kitgrose The code is looking bloated. ;( I experience the issue with the very last version of VS2022 Community & net 8 sdk. Hope this issue can be addressed as soon as possible. |
Given the following component:
You will see an error like the following:
This happens if you either click "Submit secondary" or click "Submit primary" with
?hideoptional=true
. You can work around the "Submit secondary" issue by specifying[SupplyParameterFromForm(FormName = "main-form")]
for theInputModel
, but I'm not sure about a workaround for "Submit primary" with?hideoptional=true
other than puttingIntput ??= new()
inOnInitialized()
.This came up when working on the Identity Razor components for the .NET 8 project templates. DeletePersonalData.razor and Email.razor
The text was updated successfully, but these errors were encountered: