2014-12-03 82 views
1

我正在嘗試爲Breeze的客戶端驗證使用[必需的]功能。我可以這樣做,但迄今爲止我所獲得的唯一成功就是使用字符串。我試圖用boolean來做同樣的事情,但Breeze不會識別任何實體驗證。爲什麼微風「需求」屬性驗證規則在驗證新實體時不會觸發?

這是我的域代碼段:

 [Table("Uwrl")] 
public partial class Uwrl 
{ 
    public Uwrl() 
    { 
    } 

    [Key] 
    public int customerNumber { get; set; } 

    [Required] 
    [StringLength(40)] 
    public string customerName { get; set; } 

    [Required] 
    [StringLength(50)] 
    public string customerStatus {get;set;} 


    public int? taxId {get;set;} 

    [Required] 
    public bool coAdministration{get;set;} 

這是我的控制器的代碼段來測試驗證錯誤:

  var testEntity = UWRLService.createEntity(entityName, uwrl.customerData); 
      if (!testEntity.entityAspect.validateEntity()) { alert("Didn't VALIDATE!"); } 

這是我的視圖,以確保我的特定屬性包含z驗證其中:

    <td style="text-align:right"> 
        Co-Administration:<select ng-model="uwrl.coAdministration" data-z-required> 
         <option></option> 
         <option value="True">Yes</option> 
         <option value="False">No</option> 
        </select> 
       </td> 

customerName和customerStatus都起作用。 customerStatus甚至是一個select(下拉列表) - 與共同管理屬性完全相同。如何驗證布爾值?驗證字符串對我來說是完美的...有什麼區別?

+0

只是一個猜測,但coAdministration屬性是不可空的,所以微風正在用錯誤的權利初始化它? False不爲null,因此所需的驗證不會觸發。在調用createEntity之後加入這一行來檢查:'console.log(testEntity.coAdministration)' – 2014-12-03 17:11:28

+0

所以你說的是我需要改變這個: [必需的] public bool coAdministration {get; set;} 分解爲: [需要] 公共布爾?共同管理{get; set;} – user1789573 2014-12-03 18:18:04

+0

是的,這是我的猜測 - console.log(testEntity.coAdministration)返回了什麼? – 2014-12-03 18:19:41

回答

2

布爾屬性不可空,這意味着它的初始值將是「false」。

「false」不爲null或爲空,因此所需的驗證規則未觸發。