0
有誰知道如何處理Asp.net核心中的Dropdowns。我想我讓自己很難理解新的Asp.net核心概念。 (我是Asp.net核心新手)。在ASP.net Core中填充下拉列表
我有模型叫Driver
,Vehicle
。基本上可以在主人中創建一堆車輛,然後將其附加到司機。這樣駕駛員將與車輛相關聯。
我的問題是,我也使用視圖模型在某些區域,以兩種不同的模式結合起來。(瞭解從默認模板小)
我的問題是我不知道是因爲ASP.net核心下一步是最新的,沒有很多教程和Q/A可用。
驅動程序模型
public class Driver
{
[Required]
public int Id { get; set; }
[Required]
public string ApplicationUserId { get; set; }
[Required]
public int VehicleId { get; set; }
[Required]
public string Status { get; set; }
public virtual ApplicationUser ApplicationUser { get; set; }
public virtual Vehicle Vehicle { get; set; }
}
車輛模型驅動
public class DriverViewModel
{
[Required]
[Display(Name = "ID")]
public int ID { get; set; }
[Required]
[Display(Name = "User ID")]
public string ApplicationUserId { get; set; }
[Required]
[Display(Name = "Vehicle ID")]
public IEnumerable<Vehicle> VehicleId { get; set; }
//public string VehicleId { get; set; }
[Required]
[Display(Name = "Status")]
public string Status { get; set; }
}
這裏的
public class Vehicle
{
[Required]
public int Id { get; set; }
[Required]
public string Make { get; set; }
public string Model { get; set; }
[Required]
public string PlateNo { get; set; }
public string InsuranceNo { get; set; }
}
視圖模型是我的看法
<div class="col-md-10">
@*<input asp-for="VehicleId" class="form-control" />*@
@Html.DropDownList("VehicleId", null, htmlAttributes: new { @class = "form-control"})
<span asp-validation-for="VehicleId" class="text-danger" />
</div>
感謝您的時間,我剛剛從一分鐘前來源於同一個源:) – Kirk