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, I'm working on validation rules on an ASP.NET MVC 2 project. I'm using view models and models (LightSpeed entities) to handle various scenarios. The view model manages basic validation for simple values from my forms. A controller passes the view model to a service layer where its mapped to its respective model. In the model I override OnValidate and run some business rule related validation. If I find any errors I add them to the Errors collection. A save is attempted and naturally if there were validation errors a ValidationException is thrown. The ValidationException is caught in the controller, the ASP.NET MVC ModelStateDictionary is updated with the exception's message and the screen proudly (or not) displays the error message. Here's the issue: The error message in the ValidationException isn't formatted for end user display. I could pass the service layer a reference to the ModelStateDictionary but I'd prefer the service layer not know anything about MVC components. From the controller I don't have access to the model Errors collection. Is there something I'm missing in the ValidationException that can give me the exact error string I set in the Errors collection? Is there a better way to organize the interaction above? Any help is appreciated. Thanks! |
|
|
Have a read through this post which I believe is along the lines of what you are after: http://www.mindscape.co.nz/staff/jeremy/index.php/2009/03/aspnet-mvc-part4/ Essentially if you want to provide more precise error messages using the LightSpeed validation you will need to use a custom model binder and set appropriate model errors. As indicated in that post we have a community contributed starter for this which you can download and customise as needed for your own projects which you can grab from here:
If you have any questions about this let me know :)
Jeremy |
|
|
How can I turn off any and all LightSpeed automatic validation, as mentioned here: http://www.mindscape.co.nz/forums/Post.aspx?ThreadID=2008&PostID=5289 I'm using the designer so I don't think I can just remove validation attributes. |
|
|
Use the Properties window to remove validations. Note however that if the validations correspond to database constraints then the designer will offer to recreate them when you use Update From Source. (You can also open the LightSpeed Model Explorer, then drill down into the entity > entity property > Validations folder and delete the validations directly, but this is only relevant if you have special validations that aren't surfaced through the Properties window.) |
|