jquery - Starting client-side validation when using BeginForm helper -


i working on asp.net mvc 3 application , have problem getting unobtrusive js validation work. i've asked similar question since don't answers think managed define problem better write question now.

searching answer how client-side validation working saw there must code attached click event of submit button start validation process. i'm not 100% sure so, , in fact problem, if i'm correct me js need add validation process can triggered.

this form :

@using (html.beginform("recievedatafromdocument", "forms", formmethod.post)) {     @html.validationsummary(true)     <table border="1">         <colgroup>             <col span="1" style="width: 10%;" />             <col span="1" style="width: 40%;" />             <col span="1" style="width: 25%;" />             <col span="1" style="width: 25%;" />         </colgroup>         @html.partial("_partialheader", model)         @html.partial("_partialdrawing", model)         @html.partial("_partialbody", model)         @html.partial("_partialfooter", model)     </table>     if (viewbag.status == 1)     {         <button type="submit" id="submitdocument">save</button>        }     else     {          @html.actionlink("back", "index")     } } 

and @ bottom of same view have js :

<div> <script type="text/javascript">     $(document).ready(function () {         $('#submitdocument').click(function () {             window.alert('hi');             var test = ($("form").valid());             window.alert('bye');         })     }); </script> </div> 

from i've tested till can see hi message if comment never bye. appreciated.

p.s

i have included in _layout page :

<script src="@url.content("~/scripts/jquery-1.8.3.min.js")" type="text/javascript"></script>     <script src="@url.content("~/scripts/jquery-ui-1.10.3.custom.min.js")" type="text/javascript"></script>     <script src="@url.content("~/scripts/plugins/jqgrid/jquery-ui-1.8.16.custom.min.js")" type="text/javascript"></script>     <script src="@url.content("~/scripts/pagehelpers/jqdatetimepicker.js")" type="text/javascript"></script>     <script src="@url.content("~/scripts/plugins/jquery.validate.unobtrusive.js")" type="text/javascript"></script>     <script src="@url.content("~/scripts/plugins/jquery.validate.js")" type="text/javascript"></script> 

and tried explicitly include :

 <script src="@url.content("~/scripts/plugins/jquery.validate.unobtrusive.js")" type="text/javascript"></script>  <script src="@url.content("~/scripts/plugins/jquery.validate.js")" type="text/javascript"></script> 

in view. set-up it's not working.

you need include jquery , jquery validate plugin scripts on page.

if include asp.net mvc unobtrusive validation script, happen automatically.

edit: need include unobtrusive validation script after jquery validate, or automatic setup won't work.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -