4
對於使用.NET的MVC 3中的boolean
屬性,我該如何要求值True
? 這是我在哪裏,我需要的值是True
othewise它不是有效對於MVC .net屬性上的必需屬性爲True的布爾值
<Required()> _
<DisplayName("Agreement Accepted")> _
Public Property AcceptAgreement As Boolean
這裏是在情況下,修復鏈接死亡哪天
添加該類
Public Class BooleanMustBeTrueAttribute Inherits ValidationAttribute
Public Overrides Function IsValid(ByVal propertyValue As Object) As Boolean
Return propertyValue IsNot Nothing AndAlso TypeOf propertyValue Is Boolean AndAlso CBool(propertyValue)
End Function
End Class
添加屬性
<Required()> _
<DisplayName("Agreement Accepted")> _
<BooleanMustBeTrue(ErrorMessage:="You must agree to the terms and conditions")> _
Public Property AcceptAgreement As Boolean
我知道這是舊的,但如果你添加你的解決方案作爲答案,我會upvote :) – JMK