开发者

ASP.NET MVC & ADO.NET Entity Framework clientside validation

Using aspnet mvc2 with the model auto-generated by entity frame开发者_Go百科work:

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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜