我正在使用一個ViewModel進行兩項操作:創建和更新。 但是字段asp mvc viewmodel驗證屬性
CommonFile
(具有所需屬性)位於創建視圖。所以ModelState.IsValid在更新操作中是錯誤的。如何在這兩個視圖中使用一個模型視圖?
public class UnitViewModel
{
public int Id { get; set; }
[Required(ErrorMessage = "Required field")]
[StringLength(256, ErrorMessage = "SomeMessage")]
public string Title { get; set; }
public string Code { get; set; }
[Required(ErrorMessage = "Required field")]
[DateAttribute(ErrorMessage = "Incorrect date format")]
public string MapDeadline { get; set; }
public int InAllCount { get; set; }
public int LoadedCount { get; set; }
[Required(ErrorMessage = "Required field")]
[FileAttribute(AllowedFileExtensions = new string [] { ".xls", ".xlsx" })]
public HttpPostedFileBase CommonFile { get; set; }
}