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
|
Lightspeed 4 in use - pro licence. Guidance is appreciated I'm adding non obtrusive data validation to an MVC project A field in the database, say NiNumber (datatype = varchar) is mapped to _niNumber (datatype = string) in the Model via Lightspeed When the server validation runs, the message: "NiNumber is required" is displayed in the view. That's great. However, rather than display the fieldname as this will often be non-descriptive to the user, I would like to display a custom message, say, "National Insurance Number is required" Looking on the web shows that you can do this using: [Display(Name="National Insurance Number")] [Required] public string _niNumber {get; set;} mapping to lightspeed generated model:
This works and produces my "user friendly" message..."National Insurance Number"....great. The old style message: "NiNumber is required" is displayed if [Required] is omitted:
If I add my annotations to the Lightspeed model and then regenerate the model (say add an additional field to the table containing the NI Number) I lose my custom Annotations....gulp! What and is there an approach to take in this circumstance? |
|
|
Hi Douglas, You have two options here:
I would recommend this option given what you are doing above.
This approach would be more useful if you want to add any additional logic into the property accessors as well.
|
|
|
Hi Jeremy I'll be taking the first route you recommended This works great but I have a further question: The validation attributes are added however the Namespace: data annotations is not being added On generation of the new model. Is there somewhere in Lightspeed I need to add this or do I add it to the list in the mvc configuration file? Thanks |
|
|
You mean the namespace is not appearing in the generated LightSpeed model code? Either:
|
|
|
Thanks Ivan, Those answers are just what I need. Regards |
|