Tôi có một ViewModel có chứa những điều sau đây: Cách thích hợp để đặt giá trị mặc định cho ViewModel trong MVC4?
public class CreateCardViewModel
{
[HiddenInput(DisplayValue = false)]
public int SetId { get; set; }
[Required]
public IList<Side> Sides { get; set; }
[Required]
public int Stage { get; set; }
[Required]
[DataType(DataType.Date)]
[HiddenInput(DisplayValue = false)]
public DateTime DateCreated { get; set; }
[Required]
public bool IsReady { get; set; }
}
mô hình
là như sau:public class Card
{
public virtual int CardId { get; set; }
// belongs to a Set
public virtual int SetId { get; set; }
public virtual Set Set { get; set; }
// has Sides
public virtual IList<Side> Sides { get; set; }
// is in a certain Stage
public virtual int Stage { get; set; }
// is ready to study
public virtual bool IsReady { get; set; }
public virtual DateTime DateCreated { get; set; }
}
Làm thế nào tôi có thể thiết lập một giá trị mặc định cho DateCreated?
Phương thức có thay đổi không nếu tôi muốn chèn Mặt trống vào Mặt khi tạo thẻ?