Validation of Guid

前端 未结 8 911
忘了有多久
忘了有多久 2020-12-31 02:47

I have a strongly-typed view which has a DropDownListFor attribute on it.

Each item in the dropdown list is represented by a GUID.

What I\'m after is a way

8条回答
  •  旧时难觅i
    2020-12-31 03:46

    Bad answer. See below...

    Using a regex to block empty / default Guid worked for me. Use in combination with 'Required'. I.e.

        [Required]
        [RegularExpression("^(?!(00000000-0000-0000-0000-000000000000)$)", ErrorMessage = "Cannot use default Guid")]
        public Guid Id { get; set; }
    

    EDIT: Actually this doesn't work. It rejects everything. I'll leave this answer so others don't bother trying it.

提交回复
热议问题