-
Notifications
You must be signed in to change notification settings - Fork 25.2k
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
model binding multiple sources to a single class doesn't work as doumented #29295
Comments
None of the code you posted is in this tutorial. Please reproduce a problem with the code in this tutorial. From the article: The following controller action uses the DateRange class to bind a date range:
|
The code I posted is an extended example to show the problem. In the article at section Sources the example shows:
When using the class in a controller method like this...
...the property When the instructor class is attributed with a
...the When the
...a 400 error is returned, stating: "The JSON value could not be converted to System.Int32..." Keeping The only solution I found is to put the body parameter(s) in a separate class...
... and use
Without So, the example doesn't work and the only working solution is not presented. Additionally, the example from the article is not displayed correctly in Swagger UI. The query parameter is displayed as part of the body! |
@serpent5 @sammychinedu2ky @fiyazbinhasan please review |
Yes, this is correctly stated. But, even if '[FromBody]' is not stated as in the example above it doesn't work either, because it is added as a convention. I just listed all options and outcomes in my post. My main point is that there is no way of getting the stated example to work with the information given in the article. The critical information to make this example work is not obvious and no where found in the article. It is only stated that it won't work with `[FromBody]', but not how to make it work. How do you make this example from the sources section above work? Please tell me and then state it in the article.
I even didn't know that it is possible before I saw the example and then failed when trying it out. I lost a week of my time just to figure out how it works by testing all options instead of reading a good documentation for 10 mins. Here is another workaround, creating a custom |
ooh yh you're right |
This issue has been automatically closed due to no response from the original author. Feel free to reopen it if you have more information that can help us investigate the issue further. |
The first example under the section sources shows that you can mix various sources into one model. This does not work!
E.g.
Calling the endpoint creates an error stating that Artist must not be empty.
To make it work either the following option must be set
or (from .Net 6 on?) the method parameter must be declared as [FromQuery]:
This is totally missing in the documentation and cost me several days to figure out.
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: