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
|
Hi, When using unobtrusive client validation in MVC, non-nullable associations are not checked (they do not generate validation markup). Other validations defined using attributes work well. Are there any workarounds to this issue? Thanks. |
|
|
That is correct, we only generate data annotation markup to correspond with the validation attributes. But I am a little unclear what you are looking to achieve. Are you wanting to validate that you have an entity assigned on the non nullable association? (If so, you can handle this this by checking Entity.IsValid), or do you want to check that the associated entity is also valid? (If so, presumably it is being unbound and checked for validation at the same time?) If you can give an example of what you are hoping to achieve and what is not happening that would be useful to try and help further.
|
|
|
Let's say I have a form with textboxes and a combobox that maps to the required association ID. With unobtrusive validation enabled, all other fields are checked EXCEPT for this combobox (i.e., it does not display a message such as "required field" if the user doesn't select anything and tries to submit the form) This pretty much defeats the purpose of using client-side validation. Without client-side validation, Entity.IsValid contains the right information. I hope this clarifies the situation. Thanks! |
|
|
Thanks for the clarification - yes the field wont have any DataAnnotation attributes emitted for validation because the field itself does not have any validation attributes applied. (We check for presence on associations separately for checking the validation attributes). Our DataAnnotation provider only handles translating Validation attributes for now - Ill add this to the backlog for improvement but its not going to be a quick fix unfortunately. You should be able to work-around this though by applying the ValidationPresence attribute to the field manually. You can do this in one of two ways; if you want to do this on a case by case basis you can check the Generation option on the association to be "None" and then manually implement the field and association property (just start by copy and pasting the previously generated code) and then you can pop a [ValidatePresence] attribute on the field declaration which should then be translated into the required DataAnnotation attribute. If you want to do this on a more global basis then you can modify the code generation templates to always add a [ValidatePresence] attribute to the field. The downside in both cases is that if you did have a validation issue server side you are going to see multiple errors popping up regarding the association not being assigned.
|
|