这应该很简单。我正在尝试在 IServiceCollection 上运行AddViewLocalization和AddDataAnnotationsLocalization,但正在获取
“'IServiceCollection'不包含针对 “ AddViewLocalization”和最佳扩展方法重载 'MvcLocalizationMvcBuilderExtensions.AddViewLocalization(IMvcBuilder, LanguageViewLocationExpanderFormat,操作)' 需要类型为'IMvcBuilder'的接收器”
代码:
services.AddLocalization(o =>
{
o.ResourcesPath = Const.LocalizationResourcePath;
})
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix, options => options.ResourcesPath = Const.LocalizationResourcePath)
.AddDataAnnotationsLocalization();
在更新到asp.net core 2.1之前,它工作得很好
我需要引用什么程序集?
答案 0 :(得分:2)
您正在这样做:
services.AddViewLocalization();
实际上应该在哪里调用AddViewLocalization()
方法作为AddMvc()
的扩展,例如:
services.AddMvc()
.AddViewLocalization();
答案 1 :(得分:0)
最终获得此解决方案:
services.AddLocalization(o =>
{
o.ResourcesPath = Const.LocalizationResourcePath;
})
.AddMvc()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix, options => options.ResourcesPath = Const.LocalizationResourcePath)
.AddDataAnnotationsLocalization();