ASP.NET MVC 3 RC 2 client side validation with globalization

前端 未结 2 1970
后悔当初
后悔当初 2021-02-03 10:53

My goal is to validate a user input on the client-side, depending on the users\' culture.

I have a primitive data-model with the following structure:

pub         


        
相关标签:
2条回答
  • 2021-02-03 11:09

    I had to disable the UnobtrusiveJavaScript. The page does not react instantly anymore, but at least it works.

    You can disable by default in the Web.Config.

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

    And I use the Microsoft scripts for validation:

    MicrosoftAjax.js
    MicrosoftMvcAjax.js
    MicrosoftMvcValidation.js
    

    And also the jquery-1.4.4.min.js & jquery.glob thing, but I think I use them internally. The validation is being done by the MS scripts.

    0 讨论(0)
  • 2021-02-03 11:10

    Unfortunately there's a naming conflict between jQuery.validate.format and jQuery.Globalization.format functions. Therefore you'll have to change your code to use the non-jquery Globalization plugin.

    I just wrote a blog post about it here.

    For you it should look like this:

    <script src="@Url.Content("~/Scripts/globalization.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/globinfo/Globalization.de-DE.js")" type="text/javascript"></script>
    <script type="text/javascript">
    $.validator.methods.number = function (value, element) {
        if (!isNaN(Globalization.parseFloat(value))) {
            return true;
        }
        return false;
    }
    $(document).ready(function () {
        $.culture = jQuery.cultures['de-DE'];
        $.preferCulture($.culture.name);
        Globalization.preferCulture($.culture.name);
    });
    </script>
    

    That should be enough.

    0 讨论(0)
提交回复
热议问题