返回ObjectResult结果为406不可接受 [英] Returning ObjectResult results in 406 Not Acceptable

查看:113
本文介绍了返回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.

推荐答案

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不可接受的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆