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
3.0.0 preview 2 Razor Components: "InputFormatters" is empty when making Web API POST #7438
Comments
We're in the midst of adding JSON formatters based on System.Text.Json. In the meanwhile you have to manually add back the JSON.NET based ones to your application.
|
There it is, thank you! |
* Handle OPTIONS requests without a handler in Razor Pages Fixes dotnet#7438
the .AddNewtonsoftJson() approach is working ... but when trying to add a content-type to the json input formatter as shown below, the InputFormatters is empty during AddMvc config time, probably because it is not added until the .AddNewtonsoftJson() any thought on how to work around this or if something else is wrong in the code below?
|
To fix the problem use:
|
aha ... very very nice |
What is the equivalent way of doing the following in preview 7 if I want to be able to MediaTypeFormatterCollection formatters = new MediaTypeFormatterCollection();
formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/vnd.xxx.v1+json"));
TokenResponse token = await tokenResponse.Content.ReadAsAsync<TokenResponse>(formatters); |
Hi, it looks like you are posting on a closed issue/PR/commit! We're very likely to lose track of your bug/feedback/question unless you:
Thanks! |
With a new "Razor Components" project using .NET Core 3.0.0 preview 2, I am trying to make an Http call to a controller on the server to save game data to a SQLite database. But, any POST call that I to do to a controller method with a [FromBody] parameter attribute, I get the following error: `System.InvalidOperationException: 'Microsoft.AspNetCore.Mvc.MvcOptions.InputFormatters' must not be empty. At least one 'Microsoft.AspNetCore.Mvc.Formatters.IInputFormatter' is required to bind from the body.
I see that a JsonInputFormatter should be included by default when I register the MVC services, but for some reason there are no InputFormatters in the context.
To test this, I created a brand new Razor Components project under .NET Core 3.0.0 templates.
I registered MVC and HttpClient services on my Server.Startup class:
I created a CounterController class on my Server with a simple test method:
And updated the Counter.cshtml file to inject the Httpclient and make a call to our controller:
I can use [FromQuery] parameters and everything works fine, but I just cannot get sending JSON to work because of this error. I verified that the request is being made with the correct content type and the body is valid JSON. I'm also learning Blazor as I go here and don't have a solid background with MVC/Razor pages, so it's very possible I'm just doing something wrong. My goal is to have a web game that can persist game data to a database on the server. I figured I would have my EF dbcontext datalayer and my web api controller living on the server to accept client calls for saving/updating game state.
Full stacktrace:
The text was updated successfully, but these errors were encountered: