15

MVC pages with culture depending on the user. In Search option (search can be done by DueDate), I need to have a mask on that DueDate text box. Mask must be dependant on the user's culture. In both js and cshtml have an error saying: mask.split is not a function. Changed my jquery.maskedinput-1.2.3.js from make.split to make.toString().split and the error is gone, but must looks like this: [object Object] or has some 01 numbers. Any idea? Code in cshtml looks like this:

   <script type="text/javascript">
    $(function () {
        var maskFormat = @Html.CurrentDateMask();
        $(".DateBox").mask(maskFormat);
    });
   </script>
jonni
  • 338
  • 1
  • 13
agmawe
  • 151
  • 4
  • 3
    what does `@Html.CurrentDateMask()` return? I think you want it as a string: `var maskFormat = "@Html.CurrentDateMask();";` to create a Javascript string. – voigtan Dec 19 '12 at 12:21
  • it does return a string - and yes - it helps :) thank you very much :) Additional question to it - can this be done entirely in js - with no use of any outside helpers? I have a js common for different pages and instead of changing pages - I'd like to change that js... – agmawe Dec 19 '12 at 12:29

1 Answers1

1

you could have maskFormat as a global variable (put it in the window object) and then refer it to window.maskFormat inside your JS file:

cshtml file:

(function () {
    window.maskFormat = "@Html.CurrentDateMask();";
})();

and in your Javascript file:

$(function(){
    $(".DateBox").mask(window.maskFormat);
});

but be careful so you don´t add to many global variables or with a name thats easy to overwrite

voigtan
  • 8,953
  • 2
  • 29
  • 30