1
我有MVC2一個簡單的視圖模型類,它有一個MagicItem屬性:RegularExpressionAttribute沒有工作,我不知道爲什麼
public class VoodooViewModel {
[Required(AllowEmptyStrings = false,
ErrorMessage = "The Magic Item is required")]
[RegularExpression(@"^[^-]*$",
ErrorMessage = "Hyphens are not allowed in Magic Items.")]
public string MajorModel { get; set; }
}
我只是想禁止連字符此屬性,但對於生活的我我無法得到它的工作。任何人都可以看到我做錯了什麼(RequiredAttribute工作正常)?
在我看來,我所說的正則表達式「從字符串的開頭到結尾,匹配任何不是連字符的東西」。我已經在Regex測試儀here中測試過了,它可以工作 - 但不是在我的代碼中。無論我輸入多少個連字符,都無法顯示錯誤。
此問題必須在其他地方,因爲此代碼工作時,我嘗試了。 – 2011-04-20 05:37:48