简体   繁体   中英

Handle validation of EF in windows form application

I am working with EF6 to create my model .So i create my comment model as you can see here . So for CommentText i put Required with its error message .When i use MVC ,it works fine and my errors comes and showed ,but i don't know how can i handle this error in C# win Forms .I mean when the user leaves the textbox as empty the error should be showed .but i don't know how i can access the error message ?

Best regards

public partial class Comment
    {
        [DisplayName("شناسه نظر")]
        public int Id { get; set; }
        [Required(ErrorMessage = "متن نظر را وارد کنید")]
        [DisplayName("متن نظر")]
        public string CommentText { get; set; }


   public virtual ICollection<Comment> Comments { get; set; }
        public virtual Comment Comment1 { get; set; }
        public virtual Student Student { get; set; }
        public virtual Content Content { get; set; }
    }

The attributes are a MVC feature only. If you wan't this in your Web Forms application, you have to use the RequiredValidator control and set the message in that. You must do that in your aspx or ascx file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM