x First time here? Check out the FAQ
  • Avatar151posts182karma

    Enable unobtrusive validation for mvc forms

    CodeMaster2008 started this topic December 11, 2012 @ 11:58

    The form is rendered using "Html.BeginUmbracoForm()" and the model is anotated with some validation attributes, as per sugestion on this documen: http://our.umbraco.org/documentation/Reference/Mvc/forms

    Now, how can I enable client side validation so MVC can automatically wires up these validation attributes with the front-end? 


  • Avatar151posts182karma
    Comment with ID: 133482
    CodeMaster2008 posted this reply December 14, 2012 @ 12:47

    After a 24 hours shift and unable to come up with a solution (couldn't get client side validation to work) I endup creating this post.
    However, after some sleep I came back and notice some problem with my code.
    Bottom line is: there is nothing special about enabling the client side validation, just had to do the same as I do in any mvc project. 

    Web.config:

    <configuration>
      <appSettings>
        <add key="ClientValidationEnabled" value="true"/> 
        <add key="UnobtrusiveJavaScriptEnabled" value="true"/> 
      </appSettings>

    And off course, add the javascript references.

        <script src="/scripts/jquery.validate.min.js" type="text/javascript"></script>
        <script src="/scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>

    I tried to delete this post though but since the "Delete" option is not working, I updated it just for fun :-)

     


  • Avatar653posts1216karma
    Comment with ID: 151823
    Dan Diplo posted this reply June 6, 2013 @ 10:09

    Very helpful! And you can get all the jQuery files from Microsoft's CDN, too - http://www.asp.net/ajaxlibrary/cdn.ashx


  • Avatar191posts410karma
    Comment with ID: 152425
    Sébastien Richer posted this reply June 14, 2013 @ 11:30

    So as a comment here, be carefull to put in these keys in the website's web.config and not that little web.config inside the views folder. I just spent 2 hours moving those to lines to the proper place :)


Please login or Sign up To post replies