2013-07-16 31 views
0

我在我的asp.net mvc解决方案中使用了Durandal模板。这里的问题与Durandal也使用的Breeze有关。比方说,我有以下实体在我的模型:验证发生在客户端,微风实体的某些属性将在服务器端填充在BeforeSaveEntity中

public class Driver 
{ 
    [Key] 
    public int Id { get; set; } 
    [Required] 
    public string Firstname { get; set; } 
    [Required] 
    public string Lastname { get; set; } 
    public string Comment { get; set; } 
    public int? CreatedById { get; set; } 
    public DateTime? CreatedTime { get; set; } 
    public int? UpdatedById { get; set; } 
    public DateTime? UpdatedTime { get; set; } 

    public virtual User CreatedBy { get; set; } 
    public virtual User UpdatedBy { get; set; } 
} 

正如你所看到的,我必须用于跟踪时间和用户ID(UpdatedById,UpdatedTime,...)创建/更新的一些属性。我想让用户在某些数据输入页面中编辑/创建我的驱动程序,然后在BeforeSaveEntity方法中自动填写这些属性(UpdatedById,UpdatedTime,...)服务器端。

它的工作原理,但正如你所指出的,我不得不允许在int?DateTime?这样的属性上允许为空,因为在添加一个新实体的情况下(一切都是空白的),如果我没有这样做,验证失败。

我的问题:有另一种解决方案或东西可以做,以避免使用我的模型(int? - DateTime?)可空类型为这些属性,其跟踪我创建/编辑?

谢谢。

回答

0

使它们不可空,并在每个类型的“注册”ctor中填写客户端的“虚拟”值,然后在服务器上被覆盖。

相关问题