在学习 Scott Allen 的 Pluralsight 课程“Asp.net Core 1.0 基础知识”时,在“MVC 框架中的控制器”模块和“操作结果”部分中,我在 Index 操作方法上遇到了 406 Not Acceptable 错误,该错误返回带有模型对象的 ObjectResult。
This 博客文章 https://manuel-rauber.com/2016/02/15/back-to-the-roots-creating-thin-webapis-using-the-core-of-aspnet-core/让我参考 IMvcCoreBuilder 并添加 JSON 格式化程序,如下所示:
public void ConfigureServices(IServiceCollection services)
{
var mvcCore = services.AddMvcCore();
mvcCore.AddJsonFormatters();
services.AddSingleton(provider => Configuration);
services.AddSingleton<IGreeter, Greeter>();
}
这让我可以继续。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)