How to make globalization work with MVC2 and jquery?

I am trying to do some globalization in an asp.net mvc2 application but cannot make it work completely. I am using the http://github.com/nje/jquery-glob library as a tool to display currencies and dates, etc. In accordance with the wishes of users. However, something is bothering me. The IU cannot get client / server side validation to actually accept globalization using jQuery. No matter what I try, if I send back at 40.00, everything works fine, but if I send 40.00, it is taken as 0 (not a valid decimal value. NET-invariant). I tried to follow the @haracked guide

This is in global.asax for server side processing:

private void SetCulture(string currencySymbol)
{
    AjaxHelper.GlobalizationScriptPath = 
        http://ajax.microsoft.com/ajax/4.0/1/globalization/";

    var culturePref = "sv-SE";
    var request = HttpContext.Current.Request;

    if (request.UserLanguages == null)
        return;

    var lang = request.UserLanguages[0];
    if (lang != null) {
        try {
            Thread.CurrentThread.CurrentCulture =
                CultureInfo.CreateSpecificCulture(lang);
        }
        catch {
            Thread.CurrentThread.CurrentCulture = 
                new CultureInfo(culturePref);
        }
    }

    Thread.CurrentThread.CurrentUICulture = 
        Thread.CurrentThread.CurrentCulture;
}

:

<script src="/Scripts/jquery-1.4.2.js" type="text/javascript"></script>
<script src="/Scripts/jquery.glob.js" type="text/javascript"></script>
<script src="/Scripts/globinfo/jquery.glob.sv-SE.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $.culture = jQuery.cultures['sv-SE'];
        $.preferCulture('sv-SE');
    });
</script>
<script src="/Scripts/jquery.validate.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.pack.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcJQueryValidation.js" type="text/javascript"></script>
<script src="/Scripts/jquery.metadata.js" type="text/javascript"></script>

, . . , . jQuery , 40,00, 0.00.

function globalizePage(culture) {
    // Set culture from select list
    $.preferCulture(culture);

    $("input[id$='Date']").val(function () {
        var dateString = $(this).val();
        var date = Date.parse(dateString);
        var dt = $.format(date, 'd', culture.name);
        return dt;
    });

    $("input[id$='Price']").val(function () {
        var price = $.parseInt($(this).val());
        var retVal = $.format(price, 'c', culture.name);
        return retVal;
    });
}

, ?

+5
1

, . , , , jquery.validate jquery.glob , "format", validate glob, validate.format, . , . javascript jquery , . MicrosoftMVCjQueryValidation, .

<script src="https://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="https://ajax.microsoft.com/ajax/jQuery.Validate/1.7/jQuery.Validate.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.glob.js" type="text/javascript"></script>
<script src="/Scripts/globinfo/jquery.glob.sv-SE.js" type="text/javascript"></script>
<script src="/Scripts/jquery.forms.js" type="text/javascript"></script>
+3

All Articles