Pass C# variable to helper function in jsrender template

Viewed 434

I need to pass one of my model value to the function in jsrender template. I tried using @ for accessing the C# variable, but its not working. Below is my code

<script type="text/x-jsrender" id="TemplateDate">>
 {{:~formatTemplateDate(Model.EstimatedCompletionDate)}} 
</script>

This is my helper function.

$.views.helpers({
    formatTemplateDate: function (dateEstimated) {
        "use strict";
        if (dateEstimated !== null) {
            if (!isSafari) {
                var options = {
                    year: "numeric",
                    month: "short",
                    day: "numeric",
                    hour: "2-digit",
                    minute: "2-digit"
                };
                return dateEstimated.toLocaleTimeString("en-us", options);
            } else {
                return dateEstimated;
            }
        } else {
            return null;
        }
    }
});

This is the error i get in the page

Error: n.toLocaleDateString is not a function.

Thanks in advance.

Dinesh.

2 Answers
Related