Returning ObjectResult results in 406 Not Acceptable

ε祈祈猫儿з 提交于 2019-12-22 04:15:29

问题


While following along with Scott Allen's Pluralsight course, "Asp.net Core 1.0 Fundamentals", in the "Controllers in the MVC Framework" module and "Action Results" section I ran into a 406 Not Acceptable error on my Index action method that returned an ObjectResult with a model object.


回答1:


This blog post led me to making a reference to the IMvcCoreBuilder and adding the JSON formatter 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.



来源:https://stackoverflow.com/questions/38613714/returning-objectresult-results-in-406-not-acceptable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!