2

I'd like depending of a property of the model (using ASP.NET MVC 3 with razor) in a jQuery function use :

jQuery.datepicker.setDefaults(jQuery.datepicker.regional['xx']);

or

jQuery.datepicker.setDefaults(jQuery.datepicker.regional['yy']);

Any idea ?

Thanks,

1
  • You need to give some more information here.. What exactly are you trying to achieve here? Commented Mar 16, 2011 at 19:51

1 Answer 1

7

So you could either put in in a global variable. So in your view, put something like this:

<script language="javascript" type="text/javascript">
    var userRegion = '@Model.UserRegion';
</script>

Then in your external script you can just use the userRegion global variable.

Another approach could be to use the jQuery.data() method.

So in your view, attach the user's region value to any html element - body is a good one. And then you can get it in your external javascript files.

E.g. your view... probably layout page (in which case you should put it in the ViewBag)

<html>
    <head>
        <!--blah-->
    </head>
    <body data-user-region="@(string.IsNullOrWhiteSpace(ViewBag.UserRegion) ? "en" : ViewBag.UserRegion)">
        <!--blah-->
    </body>
</html>

Then you can grab it like so:

var userRegion = jQuery.data(document.body, 'user-region');
jQuery.datepicker.setDefaults(jQuery.datepicker.regional[userRegion]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.