0
votes

Using aspnet mvc2 with the model auto-generated by entity framework:

Is it possible to tell entity framework to auto-annotate all fields? eg:

If database field says not null then add [Required] If DB field is a nvarchar(x) then add [StringLength(x)]

And so on?

What if the field name contains the string "email" eg CustomerEmail - can I get EF to auto-annotate that with an appropriate annotation ([Regex()] maybe)

As I understand it, if the model fields are annotated, and I use both Html.ValidationMessageFor() and use if (ModelState.IsValid) in my controller, then that is all I need to do to have basic clientside input validation working?

Thanks

2
Yes, its a duplicate - I didn't see the older question because its question and tags are too vague. The answer in that question hasn't helped either. - JK.

2 Answers

1
votes

I am not aware of any automatically generated attributes.

As I understand it, if the model fields are annotated, and I use both Html.ValidationMessageFor() and use if (ModelState.IsValid) in my controller, then that is all I need to do to have basic clientside input validation working?

That is correct. http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-2-modelmetadata.html

0
votes

in jQuery, you can run through every object in a page. If it's client side validation you're looking for, you can use jQuery's field validation.