我尝试使用ASP.Core来建立一个多语言网站.所以,我有我的StartUp.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddLocalization();
services.Configure<RequestLocalizationOptions>(
opts =>
{
var supportedCultures = new[]
{
new CultureInfo("de-DE"),
new CultureInfo("de"),
new CultureInfo("fr-FR"),
new CultureInfo("fr"),
};
opts.DefaultRequestCulture = new RequestCulture("fr-FR");
// Formatting numbers, dates, etc.
opts.SupportedCultures = supportedCultures;
// UI strings that we have localized.
opts.SupportedUICultures = supportedCultures;
});
// Add framework services.
services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
}
Run Code Online (Sandbox Code Playgroud)
在我的_ViewImports.cs中我有:
@using System.Threading.Tasks
@using Microsoft.AspNetCore.Builder
@using Microsoft.AspNetCore.Localization
@using Microsoft.AspNetCore.Mvc.Localization
@using Microsoft.Extensions.Options …Run Code Online (Sandbox Code Playgroud) asp.net globalization localization asp.net-mvc-4 asp.net-core
我想像示例一样填充图表:https://www.chartjs.org/docs/latest/charts/bar.html
我收到此错误:
AttributeError at /timesheet/json-month/
Got AttributeError when attempting to get a value for field `working_hour` on serializer `TimesheetSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `str` instance.
Original exception text was: 'str' object has no attribute 'working_hour'.
Run Code Online (Sandbox Code Playgroud)
有了这个模型:
class Timesheet(models.Model):
owner = models.ForeignKey(User, on_delete = models.CASCADE)
title = models.CharField(max_length = 64, verbose_name = _("Title"))
date = models.DateField(default=datetime.datetime.now())
working_hour = models.FloatField(verbose_name = _("Working time"))
week = models.IntegerField(verbose_name = "working week") …Run Code Online (Sandbox Code Playgroud) 我将Asp.Core 2.1与“ Page Razor Crud”一起使用,并且希望在我的页面中显示一个下拉列表。
这是我的模型:
public enum EnumStatus
{
Waiting,
[Display(Name = "Development progress")]
Progress,
Canceled,
Refused,
Deployed,
}
public class Improvement
{
[Key]
public int ID { get; set; }
public string Title { get; set; }
[DataType(DataType.Text)]
public string Description { get; set; }
public EnumStatus Status { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
CRUD Razor页面生成了以下行:
<select asp-for="Improvement.Status" class="form-control"></select>
Run Code Online (Sandbox Code Playgroud)
但它是空的。经过研究,我发现我需要添加asp项目。但是在这一点上,我测试过的所有解决方案都失败了。
最好的祝福,