当我从Web项目中使用模型时,它就起作用了。
所以我的问题是如何翻译来自不同模型项目的模型数据注释验证。
我的项目结构如下。
Startup.cs
services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; });
services.AddMvc()
.AddViewLocalization(
LanguageViewLocationExpanderFormat.Suffix,
opts => { opts.ResourcesPath = "Resources"; })
.AddDataAnnotationsLocalization();
services.Configure<RequestLocalizationOptions>(
opts =>
{
var supportedCultures = new List<CultureInfo>
{
new CultureInfo("en-GB"),
new CultureInfo("nl-NL"),
};
opts.DefaultRequestCulture = new RequestCulture("nl-NL");
// Formatting numbers, dates, etc.
opts.SupportedCultures = supportedCultures;
// UI strings that we have localized.
opts.SupportedUICultures = supportedCultures;
});
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => false;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
//var options = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
//app.UseRequestLocalization(options.Value);
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "uploads")),
RequestPath = "/uploads"
});
app.UseCookiePolicy();
app.UseSession();
app.UseMvc();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
我如何翻译模型数据注释验证。 预先感谢
答案 0 :(得分:0)
如果要转换模型数据注释验证并且模型类库项目不同(模型类文件不是Web Project的一部分),则需要在模型类库项目中创建相同的“资源”文件夹。