asp.net mvc - MVC 4 validation message from entityconfiguration -



asp.net mvc - MVC 4 validation message from entityconfiguration -

this attributes model need validation.

public system.datetime entrydate { get; set; } public system.datetime deadline { get; set; } public string client { get; set; } public string customercontact { get; set; }

this entitytypeconfiguration validation these attributes.

this.property(t => t.entrydate) .isrequired(); this.property(t => t.deadline) .isrequired(); this.property(t => t.customer) .isrequired() .hasmaxlength(20); this.property(t => t.customercontact) .isrequired() .hasmaxlength(20); this.property(t => t.intercontact) .isrequired() .hasmaxlength(20); this.property(t => t.category) .isrequired() .hasmaxlength(5);

how work

@html.validationmessagefor(model => model.deadline)

the validation rules set within entity mapping don't bubble ui you're suggesting in code. rules you've specified used create , validate entity before saving database.

if wish validate entity using @html.validationmessagefor() helper occurs on ui layer , instead uses asp.net mvc's info annotations set validation rules, so:

public class product { [stringlength(50),required] public object name { get; set; } [stringlength(15)] public object color { get; set; } [range(0, 9999)] public object weight { get; set; } }

ultimately, want treat entity separate object gets passed ui, mapping entity view specific model such view model. you're able add together validation attributes highlighted in reply above view model there may circumstances 1 form requires field required, form might not.

asp.net-mvc asp.net-mvc-4 validation

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -