本文介绍了返回ObjectResult结果为406不可接受的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在遵循"MVC框架中的控制器"模块和操作结果"部分中的Scott Allen的Pluralsight课程"Asp.net Core 1.0基础知识"的同时,我在Index操作方法上遇到了406 Not Acceptable错误返回了带有模型对象的ObjectResult.
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.
推荐答案
此博客文章使我引用了IMvcCoreBuilder并添加了JSON格式化程序,如下所示:
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>();
}
这使我得以继续.
这篇关于返回ObjectResult结果为406不可接受的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!