Returning ObjectResult result in 406 is invalid

Following along with Scott Allen Pluralsight, “Asp.net Core 1.0 Fundamentals,” in the “Controllers in the MVC Framework” and “Action Results” module, I encountered a 406 Not Acceptable error in the index action method that returned ObjectResult with the model object.

+7
c # asp.net-core asp.net-core-mvc
source share
2 answers

This blog post led me to a link to IMvcCoreBuilder and add JSON formatting as follows:

public void ConfigureServices(IServiceCollection services) { var mvcCore = services.AddMvcCore(); mvcCore.AddJsonFormatters(); services.AddSingleton(provider => Configuration); services.AddSingleton<IGreeter, Greeter>(); } 

which allowed me to continue.

+11
source share

@json gives the correct answer, which should be marked as accepted:

This solved my problem: services.AddMvcCore (). AddJsonFormatters ()

+3
source share

All Articles