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 Guys, Could you let me know if you have any MVC2 examples with clientside JQuery validation? I have quickly set something up - but it not exactly working as expected, taking a simple example like this... <% using (Html.BeginForm()) {%> <%=Html.ValidationSummary(true) %> <fieldset> <legend>Please enter details here...</legend> <div class="editor-label"> Your name </div> <div class="editor-field"> <%= Html.TextBoxFor(model => model.Name) %> <%= Html.ValidationMessageFor(model => model.Name) %> </div> <div class="editor-label"> Email </div> <div class="editor-field"> <%= Html.TextBoxFor(model => model.Email) %> <%= Html.ValidationMessage("Email")%> </div> <div class="editor-label"> Accept terms </div> <div class="editor-field"> <%= Html.CheckBoxFor(model => model.AcceptTerms) %> <%= Html.ValidationMessageFor(model => model.AcceptTerms)%> </div> </fieldset> <% } %> Where All fields are required and not null... Client side validation works for the checkbox, and the "ValidationMessageFor" message displays. Client side validation does nothing for the Name and Email Server side validation works for Name and Email - but the error messages are displayed in a single <LI>, separated by newline, rather than in separate <LI>'s How do I make the client side validation work for the string type values, and also have the server side validation output separate <li>'s - or do I have to manually do it in the controller? Cheers for your help guys! |
|
|
We dont have a specific MVC2 sample leveraging those helpers which I can point you to unfortunately but hopefully here are a couple of things to get you going; For the server side validation - you will want to use a custom model binder which emits the errors from LightSpeed validation more precisely rather than the leveraging the DefaultModelBinder behavior. Have a look at either directly using or adapting the EntityModelBinder from the community code library for Mvc (source repo is located at: https://code.mindscape.co.nz/repos/LightSpeed/Mvc/Trunk/Src/Mindscape.LightSpeed.Mvc/) For the client side validation, I believe this will be relying on you having appropriate Data Annotation attribute specified on your model properties, the LightSpeed validation properties alone are not sufficient for this unfortunately. At this stage you will need to manually annotate your model, however we do have a tool for automatically applying these attributes at runtime ias part of the Mindscape.LightSpeed.Web.DynamicData assembly which likely could be used in MVC to apply these automatically but at this stage we havnt confirmed if it works or have a nice sample of how to apply this :) There is some more info about this in this forum post: http://www.mindscape.co.nz/forums/Post.aspx?ThreadID=2211&PostID=6274 I will have a look at putting togethor a quick sample and see if we can leverage the EntityDataAnnotationProvider within MVC but in the meantime let us know how you get on with the suggestions above.
Jeremy |
|
|
Thanks Jeremy, If you could knock up an example it would be greatly appreciated! In the meantime I will have a look at the URLs you posted, and have a play. Cheers |
|
|
Bump. Any progress on this? |
|
|
No - but we are building out an MVC3 sample for LightSpeed 4 which covers this, so if that would be of use I can forward it on to you once its available.
Jeremy |
|
|
I have it working now, but i need some help from you guys to make it a maintainable solution. See my other post.
Sean |
|
|
Thanks for sharing this, I will have a look at formalising this back into LightSpeed more directly.
Jeremy |
|