我想知道什麼是正確的方法來解決這個問題。我目前有一個模型 - (如下所示),其中包含我的記錄所需的所有字段。一個模型只更新每個視圖中的一些字段
我的問題是,當創建記錄時,我只需要傳遞 CustomerID,EmployeeID,Date和ArrivalTime的數據。
當記錄在稍後階段更新時,模型中剩餘的字段將被填充。
由於我的一些領域是必需的,如果我不發佈這些領域的數據,這顯然會導致驗證錯誤。
我在想什麼是實現這一目標的最佳實踐?
我應該將模型分成兩個?還是可以進行部分驗證?
public class CustomerSupportRecord
{
public int CustomerSupportRecordID { get; set; }
[Required]
public int CustomerID { get; set; }
[Required]
public string EmployeeID { get; set; }
[Required(ErrorMessage = "Please enter a Date")]
[DataType(DataType.Date)]
[Display(Name = "Date")]
public DateTime Date { get; set; }
[Required(ErrorMessage = "Please select an Arrival Time")]
[DataType(DataType.Time)]
[Display(Name = "Arrival")]
public DateTime ArrivalTime { get; set; }
[Required(ErrorMessage = "Please select a Departure Time")]
[DataType(DataType.Time)]
[Display(Name = "Departure")]
public DateTime DepartureTime { get; set; }
[Required(ErrorMessage = "Please select a Type")]
[Display(Name = "Type")]
public int CustomerSupportTypeID { get; set; }
[Display(Name = "Setting")]
public string ReflectionSetting { get; set; }
[Display(Name = "Advisor")]
public string ReflectionAdvisor { get; set; }
[Display(Name = "Notes")]
public string Notes { get; set; }
[Display(Name = "Comments")]
public string Comments { get; set; }
// Navigation Properties
public virtual Customer Customer { get; set; }
public virtual CustomerSupportType CustomerSupportType { get; set; }
public virtual Employee Employee { get; set; }
}
是'CustomerSupportRecord'域之一模型還是視圖模型? – HTX9
這是一個域模型。 – Stephen