Skip to content

Conversation

@bjswick33
Copy link

After following the controller example and some debugging I had to add [FromForm] to the Remove signature before the upload would hit the controller action.

CLA Form below has been signed/submitted.

Note to external contributors: make sure to sign our Contribution License Agreement (CLA) for Blazor UI first:

https://forms.office.com/Pages/ResponsePage.aspx?id=Z2om2-DLJk2uGtBYH-A1NbWxVqugKN5DvVp8I-1AgOBURFBVSkwyMlA1TkFDVFdMNU1aM1o1UlZQOC4u

After following the controller example and some debugging I had to add [FromForm] to the Remove signature before the upload would hit the controller action.
@bjswick33 bjswick33 requested a review from a team July 27, 2022 14:46
@dimodi
Copy link
Contributor

dimodi commented Jul 28, 2022

Hello @bjswick33 ,

Thanks for your contribution!

Normally, [FromForm] should not be required and I have Blazor Server and WebAssembly test projects that both work without it. Perhaps your scenario involves model binding or some other setup, which brings the need to add [FromForm]. This thread contains a few comments that may ring a bell -

Asp.net core model doesn't bind from form

We can include [FromForm] in a note in our documentation, but we must be clear about what exactly triggers the need for this attribute? Thank you in advance for your cooperation!

@bjswick33
Copy link
Author

@dimodi

Thanks for the input. I've run through my code and I'm really only using the sample code within my application. I'm running the latest version of everything and was wondering if the need for [FromForm] for the remove was needed since my upload was within an , but after testing outside of that the code still will not fire unless the attribute is added. Are your examples public on GH so I can bring them down? Are they using .NET 6 and latest versions?

In any case I think if the code example does not include the attribute some sort of message below in the documentation may need to be included for those having a similar action when trying to use the remove (attribute not required for save). We needed to do some searching when we found a discussion on the forms where someone did this and it's working.

@dimodi
Copy link
Contributor

dimodi commented Aug 3, 2022

Hi Brun,

Here is a runnable Blazor Server app that you can compare with your implementation. Uploading and removing works without [FromForm].

UploadTest.zip

Let me know if you find what makes the difference.

@dimodi dimodi self-requested a review August 3, 2022 15:51
@bjswick33
Copy link
Author

Thanks @dimodi. I'll have to take a look in the next day or so. The application will not build and has a number of errors. Main thing jumping out at me is we are .NET 6.0 and this app cannot target 6? We are also doing a blazor server (hosted) application. I'll get back to you in a day or so.

@dimodi
Copy link
Contributor

dimodi commented Aug 3, 2022

That's strange. The test app targets .Net 6 and I specifically made it from scratch, so that it is isolated, minimal and runnable as is.

@bjswick33
Copy link
Author

Yeah No problem. I only gave it a few minutes. Pretty busy today so can't 100% focus on it today. I'll let you know what I find.

@dimodi
Copy link
Contributor

dimodi commented Aug 17, 2022

@bjswick33

Hi Brun, did you get a chance to see what makes [FromForm] required in your scenario?

@bjswick33
Copy link
Author

I'm sorry, but I have not. I've been continued working on the application and have not had time to set aside to test your example. I'm going to set aside some time tomorrow and will provide an update. Sorry it's taken this long.

@bjswick33
Copy link
Author

@dimodi I was able to run through your example today and this time it built and ran without issue. I was able to add/remove documents without the [FromForm] attribute. I will say our application is a little more complex than the sample. We are Blazor Webassembly .NET Core Hosted and have our client/api in separate projects. We also have authorization and security on our controllers. Not saying any of that is causing our scenario, but at this moment we still require [FromForm]. I'm ok with closing this out and not implementing my change to the docs, but I agree with your idea of adding it somewhere as a note so people will know when applying the example there, but I'm not sure what is exactly triggering the requirement. Again we eventually ran into a comment in the forms somewhere else that gave us the idea to put that in and it started working.

@dimodi
Copy link
Contributor

dimodi commented Aug 19, 2022

Thanks, Brun.

In this case, I suggest that we close this for now. It will look strange to document a statement that sounds a bit vague about its applicability and relevance. If by chance another customer sheds light on this, we will revisit the topic.

@dimodi dimodi closed this Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants