Enum未在Orchard中验证

时间:2012-11-26 21:04:03

标签: asp.net-mvc-3 orchardcms

我花了好几个小时试图解决这个问题。

我正在使用Orchard 1.6源和DataAnnotations。我的strings装饰有[Required]和我的enum。但是,客户端验证仅适用于我页面上的文本框(strings),enum(单选按钮列表)不会触发验证(也不会显示为class="input-validation-error" html来源)。

这是我的enum

public enum Referral
    {
        [Display(Name = "Google / Google+")]
        Google,
        [Display(Name = "Bing / Yahoo / Other Search Engine")]
        OtherSearch,
        [Display(Name = "LinkedIn")]
        LinkedIn,
    }
    public class ReferralSelectorAttribute : SelectorAttribute
    {
        public override IEnumerable<SelectListItem> GetItems()
        {
            return Selector.GetItemsFromEnum<Referral>();
        }
    }
    [Required(ErrorMessage = "Please select one referral option")]
    [Display(Name = "How did you hear about us?", 
        Description = "Letting us know how you reached us helps us 
        to focus our advertising efforts and ultimately lowers costs")]
    [ReferralSelector(BulkSelectionThreshold = 8)]
    public virtual Referral? ReferralRadioButton { get; set; }

我不确定为什么这不会解雇。有什么想法吗?

注意:我已经尝试过关于这个主题的所有内容。我已经使用特殊的ResourceManifest.cs文件注册了相应的jquery脚本(验证,不显眼等)。我把它包含在我的视野中。我在一个特殊的Shell.cs文件(IOrchardShellEvents或其他东西)中重新添加了模型验证。

1 个答案:

答案 0 :(得分:0)

解决!我将枚举和选择器拆分为它们自己的类,引用它们,然后不使用web.config来启用客户端验证,只是在视图中填充了html.helper。