我尝试使用[必需]功能进行Breeze的客户端验证。我可以这样做,但到目前为止我唯一的成功就是字符串。我试图用布尔值做同样的事,但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-validate:
<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(下拉列表) - 与coAdministration属性完全相同。如何验证布尔值?验证字符串对我来说非常有用......有什么区别?
答案 0 :(得分:2)
布尔属性不可为空,这意味着它的初始值将为“false”。
“false”不为null或为空,因此不会触发所需的验证规则。