Hi: I am using jqModal to allow users to create new contacts from a list by poping a jqModal window, but can't seem to get any validation to work within the modal window. I know that the form is failing because in the contoller the model state is invalid and when I re-render the form nothing shows. I am using ajax events to close the modal window and need to know if there is a way to validate the view before submition so I don't trigger the event that closes the window that is located on the parent form. Question is do I have to use the jQuery validation function or can I use the built in MVC 2 validation? Below is the html code I am using for the modal window
'> '> ' > // JNS - ajax scripts $(document).ready(function () { $("#ContactAddLoading").hide(); }); // This is code used to handle the tiggers for the diffrent ajax event. //.trigger('name') same as an event in asp - this will propogate through all the page models // until something catches it. function updateComplete() { $('#TextArea').trigger('UpdateComplete'); } function updateSuccess() { //$('#TextArea').trigger('ContactAddSuccess'); } function updateFail() { $('#TextArea').trigger('updateFail'); } function updateBegin() { $('#TextArea').trigger('updateBegin'); } // to use datepicker on the modal window form we must inject css information when the item is created // this code below will move the caladar above the text box since it is about 200px high, if you want to // move the calader to the right or left set the approrate margin as well // marginLeft: size marginTop size... - see stack overflow $(function () { $(".datePicker").datepicker({ showOn: 'both', buttonImage: "../../Content/Images/calendar.png", beforeShow: function (input, inst) { inst.dpDiv.css({ marginTop: '-200px' }); } }); });<% Html.EnableClientValidation(); %> <% using (Ajax.BeginForm("ContactAdd", "Contact", new AjaxOptions { OnBegin = "updateBegin", OnSuccess = "updateSuccess", OnFailure = "updateFail", OnComplete = "updateComplete" }, new { id = "form-ContactAdd" })) { %>
model.NovaContact.FirstName) %> model.NovaContact.FirstName)%> model.NovaContact.FirstName)%> model.NovaContact.LastName)%> model.NovaContact.LastName)%> model.NovaContact.LastName)%> Contact Type: model.NovaContact.Description)%> model.NovaContact.Description)%> model.NovaContact.Description)%> model.NovaContact.DataBaseTrailerAttributes.EffectiveStartDate)%> model.NovaContact.DataBaseTrailerAttributes.EffectiveStartDate)%> model.NovaContact.DataBaseTrailerAttributes.EffectiveStartDate)%> model.NovaContact.DataBaseTrailerAttributes.EffectiveEndDate)%> model.NovaContact.DataBaseTrailerAttributes.EffectiveEndDate)%> model.NovaContact.DataBaseTrailerAttributes.EffectiveEndDate)%>
<% } %>
I am using a provider pattern with an entities project that the mvc models are using. I put the anotation for validation in the entites class. The controller is just checking the Modelstate and tryes to re-render the ajax from.
Thanks