我希望 Technology Box 显示在 Create 的下拉列表中
I want Technology Box will be shown in Dropdown in Create
我希望我的技术文本框显示在下拉列表中,但class是不同的项目是一个 Class 技术是另一个 class 喜欢
public class Project
{
public int ProjectId { get; set; }
[StringLength(60, MinimumLength = 3)]
[Required]
public string? ProjectName { get; set; }
[Required]
public string? Description { get; set; }
[Required]
public DateTime Start { get; set; }
public DateTime? End { get; set; }
[Required]
public string? ProjectHead { get; set; }
[Required]
public string? Status { get; set; }
public string? Technology { get; set; }
public ICollection<ProjectTechnology>? ProjectTechnology { get; set; }
}
public class Technology
{
public int TechnologyId { get; set; }
public string? TechnologyName { get; set; }
public ICollection<ProjectTechnology>? ProjectTechnology { get; set; }
}
public class ProjectTechnology
{
public int Id { get; set; }
public int ProjectId { get; set; }
public int TechnologyId { get; set; }
public Project? Project { get; set; }
public Technology? Technology { get; set; }
}
这是我的 Css html 页面,它将使用脚手架创建我希望这将显示在从技术领域的数据库中获取数据的下拉列表中。
<div class="row">
<div class="form-group col-md-6">
<label asp-for="Technology" class="control-label"></label>
<input asp-for="Technology" class="form-control" />
<span asp-validation-for="Technology" class="text-danger"></span>
</div>
</div>
尝试
Project.cs:
public class Project
{
public int ProjectId { get; set; }
[StringLength(60, MinimumLength = 3)]
[Required]
public string? ProjectName { get; set; }
[Required]
public string? Description { get; set; }
[Required]
public DateTime Start { get; set; }
public DateTime? End { get; set; }
[Required]
public string? ProjectHead { get; set; }
[Required]
public string? Status { get; set; }
public int TechnologyId { get; set; }
public Technology Technology{ get; set; }
}
Technology.cs
public class Technology
{
public int TechnologyId { get; set; }
public string? TechnologyName { get; set; }
public ICollection<Project>? Project { get; set; }
}
在Program.cs中添加如下代码:
builder.Services.AddDbContext<MyDbContext>(options =>
options.UseSqlite(builder.Configuration.GetConnectionString("MyDbContext")));
在appsettings.json中:
"ConnectionStrings": {
"MyDbContext": "Filename= C:\Users\Administrator\sqlite\ITProjectDB.db"
}
MyDbContext:
public class MyDbContext : DbContext
{
public MyDbContext(DbContextOptions<MyDbContext> options) : base(options) { }
public DbSet<Technology> Technology { get; set; }
public DbSet<Project> Project { get; set; }
}
结果:
我希望我的技术文本框显示在下拉列表中,但class是不同的项目是一个 Class 技术是另一个 class 喜欢
public class Project
{
public int ProjectId { get; set; }
[StringLength(60, MinimumLength = 3)]
[Required]
public string? ProjectName { get; set; }
[Required]
public string? Description { get; set; }
[Required]
public DateTime Start { get; set; }
public DateTime? End { get; set; }
[Required]
public string? ProjectHead { get; set; }
[Required]
public string? Status { get; set; }
public string? Technology { get; set; }
public ICollection<ProjectTechnology>? ProjectTechnology { get; set; }
}
public class Technology
{
public int TechnologyId { get; set; }
public string? TechnologyName { get; set; }
public ICollection<ProjectTechnology>? ProjectTechnology { get; set; }
}
public class ProjectTechnology
{
public int Id { get; set; }
public int ProjectId { get; set; }
public int TechnologyId { get; set; }
public Project? Project { get; set; }
public Technology? Technology { get; set; }
}
这是我的 Css html 页面,它将使用脚手架创建我希望这将显示在从技术领域的数据库中获取数据的下拉列表中。
<div class="row">
<div class="form-group col-md-6">
<label asp-for="Technology" class="control-label"></label>
<input asp-for="Technology" class="form-control" />
<span asp-validation-for="Technology" class="text-danger"></span>
</div>
</div>
尝试
Project.cs:
public class Project
{
public int ProjectId { get; set; }
[StringLength(60, MinimumLength = 3)]
[Required]
public string? ProjectName { get; set; }
[Required]
public string? Description { get; set; }
[Required]
public DateTime Start { get; set; }
public DateTime? End { get; set; }
[Required]
public string? ProjectHead { get; set; }
[Required]
public string? Status { get; set; }
public int TechnologyId { get; set; }
public Technology Technology{ get; set; }
}
Technology.cs
public class Technology
{
public int TechnologyId { get; set; }
public string? TechnologyName { get; set; }
public ICollection<Project>? Project { get; set; }
}
在Program.cs中添加如下代码:
builder.Services.AddDbContext<MyDbContext>(options =>
options.UseSqlite(builder.Configuration.GetConnectionString("MyDbContext")));
在appsettings.json中:
"ConnectionStrings": {
"MyDbContext": "Filename= C:\Users\Administrator\sqlite\ITProjectDB.db"
}
MyDbContext:
public class MyDbContext : DbContext
{
public MyDbContext(DbContextOptions<MyDbContext> options) : base(options) { }
public DbSet<Technology> Technology { get; set; }
public DbSet<Project> Project { get; set; }
}
结果: