너무 혼란 스럽습니다. 내가 계단식 드롭 다운을 구축하기 위해 노력 중이며 가장 이상한 오류가 발생했습니다. 다음과 같은 오류가 발생합니다. (긴 것입니다) -모델 생성 중에 하나 이상의 유효성 검사 오류가 발견되었습니다. r n r n
"모델 생성 중에 하나 이상의 유효성 검사 오류가 발견되었습니다. \ r \ n \ r \ nAQB_MON.ViewModels.DeviceStatu : : EntityType 'DeviceStatu'has has been 정의 된 키가 없습니다.이 EntityType의 키를 정의하십시오. \ r \ nAQB_MON.ViewModels.SelectListItem :: EntityType 'SelectListItem'에 키가 정의되어 있지 않습니다.이 EntityType의 키를 정의하십시오. \ r \ nDeviceStatus : EntityType : EntitySet 'DeviceStatus'는 유형에 대한 'DeviceStatu'정의 된 키가 없습니다 그 \ 연구 \의 nSelectListItems :. EntityType : EntitySet 'SelectListItems'는 정의 된 키가없는 유형 'SelectListItem'을 기반으로 \ 연구 \ n을 "}
I는 제조업이있다. 테이블 및 ManufacturerModel 테이블. 계단식 드롭 다운은 제조업체를 먼저 선택한 다음 해당 모델 옵션을 두 번째 드롭 다운에서 사용할 수 있도록 구성됩니다. 그러나 드롭 다운을로드 할 때 오류가 계속 수신됩니다.
나는 내 자신의 뷰 모델 생성 -public class ManufacturerModelContext : DbContext
{
public DbSet<Manufacturer> Manufacturers { get; set; }
public DbSet<ManufacturerModel> ManufacturerModels { get; set; }
}
ManufacturerModelContext
을 나는 그것은 바르 제조업체에 실패//Populate the cascading dropdowns for manufacturer and model
ManufacturerModelContext mm = new ManufacturerModelContext();
[HttpGet]
public JsonResult GetManufacturers()
{
var manufacturer = from a in mm.Manufacturers
select a.Manufacturer1;
return Json(manufacturer.ToList(), JsonRequestBehavior.AllowGet);
}
public JsonResult GetModelsByManufacturerID(string manufacturerId)
{
int Id = Convert.ToInt32(manufacturerId);
var models = from a in mm.ManufacturerModels where a.ManufacturerID == Id select a;
return Json(models);
}
와 제조 업체 및 모델을 검색 할 수 있습니다. 이상한 것은 내가 심지어 AQB_MON.ViewModels.DeviceStatu
제조업체 모델
public partial class Manufacturer
{
public Manufacturer()
{
this.ManufacturerModels = new HashSet<ManufacturerModel>();
}
public int ManufacturerID { get; set; }
[Display(Name="Manufacturer")]
public string Manufacturer1 { get; set; }
[Display(Name="Manufacturer Description")]
public string ManufacturerDescription { get; set; }
public System.DateTime DATE_CREATED { get; set; }
public string CREATED_BY { get; set; }
public Nullable<System.DateTime> DATE_MODIFIED { get; set; }
public string MODIFIED_BY { get; set; }
public virtual ICollection<ManufacturerModel> ManufacturerModels { get; set; }
ManufacturerModel 모델
public partial class ManufacturerModel
{
public ManufacturerModel()
{
this.Devices = new HashSet<Device>();
}
public int ManufacturerModelID { get; set; }
[Display(Name="Manufacturer")]
public int ManufacturerID { get; set; }
public string Model { get; set; }
[Display(Name="Model Description")]
public string ModelDescription { get; set; }
public System.DateTime DATE_CREATED { get; set; }
public string CREATED_BY { get; set; }
public Nullable<System.DateTime> DATE_MODIFIED { get; set; }
public string MODIFIED_BY { get; set; }
public virtual ICollection<Device> Devices { get; set; }
public virtual Manufacturer Manufacturer { get; set; }
장치 모델
있었나요 한번도하지 않는다는 것입니다public partial class Device
{
public Device()
{
this.DeviceLocations = new HashSet<DeviceLocation>();
this.DeviceLogs = new HashSet<DeviceLog>();
this.DeviceStatus = new HashSet<DeviceStatu>();
}
public int DeviceID { get; set; }
[Display(Name = "Device Type")]
public int DeviceTypeID { get; set; }
public int ManufacturerModelID { get; set; }
[Display(Name="Inventory Number")]
public string InventoryNumber { get; set; }
[Display(Name = "Serial Number")]
public string SerialNumber { get; set; }
[Display(Name = "State ID")]
public string StateID { get; set; }
[Display(Name = "Date Received")]
[DisplayFormat(DataFormatString = "{0:d}", ApplyFormatInEditMode = true)]
public DateTime? DateReceived { get; set; }
public Nullable<decimal> Price { get; set; }
public string Notes { get; set; }
public System.DateTime DATE_CREATED { get; set; }
public string CREATED_BY { get; set; }
public Nullable<System.DateTime> DATE_MODIFIED { get; set; }
public string MODIFIED_BY { get; set; }
public virtual DeviceType DeviceType { get; set; }
public virtual ManufacturerModel ManufacturerModel { get; set; }
public virtual ICollection<DeviceLocation> DeviceLocations { get; set; }
public virtual ICollection<DeviceLog> DeviceLogs { get; set; }
public virtual ICollection<DeviceStatu> DeviceStatus { get; set; }
Manufacturer1은 무엇입니까? 모델을 표시하면 도움이 될 수 있습니다. –
제조업체 모델 및 ManufactureModel 모델 –
으로 내 질문을 업데이트했습니다. ManufacturerModel에 Device 참조가 있지만 DbSet이 표시되지 않습니다. DbSet을 추가하거나 [NotMapped]를 해당 탐색 속성에 추가해야합니다. –