This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I have managed to get MVC validation working with Lightspeed entities. However I needed to copy and modify DataAnnotationBuilder to do this. This is problimatic on a number of levels so it would be nice if you can make some minor (honest) changes to DataAnnotationBuilder.
The changes are: 1 Make it a public class 2 Add a constructor taking a Type, property and display name instead of a PropertyDescriptor 3 Add a GetDataAnnotations method taking Type etc instead of a Property descriptor 4 Inside DataAnnotationBuilder, refer to the type, name, display name instead of the now missing property
Ie something like public class DataAnnotationBuilder public static Attribute[] GetDataAnnotations(Type entityType, string propertyName, string displayName = null) ... } With those changes, you add validation with the following class: public class LightspeedModelValidatorProvider : DataAnnotationsModelValidatorProvider and then in global.asax.cs
protected void Application_Start()
Sean
|
|
|
Hi Sean, Thanks for the suggestion -- this seems eminently do-able but I wasn't sure where you envisaged the DisplayName being used. The existing DataAnnotationBuilder does not use _pd.DisplayName. Were you wanting to see it used instead of _pd.Name in GetErrorMessageSubstitutions? |
|
|
Yes, I saw it being used in the error messages. I haven't shown it in my sample, but I decamelise my property names to make something slightly more user friendly.
Sean |
|
|
Okay, the DataAnnotationBuilder changes will be in the next nightly. For now, you'll still need to build your own ValidatorProvider class. |
|
|
All working fine. Thanks.
|
|