I'm trying to push a C# DateTime to a javascript array. Ideally, I'd like it converted to a string. I've tried multiple different approaches but none have worked. The continual error I get is that I'm missing a ) which I can't make much sense of.
I declare a local js variable to hold the values:
var startDates = [];
I've tried:
        @foreach (var d in Model.Items)
        {
            @:startDates.push(Date(@d.StartDate.Date));
        }
and
        @foreach (var d in Model.Items)
        {
            @:startDates.push(Date(@d.StartDate));
        }
and
        @foreach (var d in Model.Items)
        {
            @:startDates.push(@d.StartDate);
        }
and
        @foreach (var d in Model.Items)
        {
            @:startDates.push(Date(@d.StartDate.ToString()));
        }
and
        @foreach (var d in Model.Items)
        {
            @:startDates.push(new Date(@d.StartDate.Date));
        }
and
        @foreach (var d in Model.Items)
        {
            var date = d.StartDate.ToString();
            @:startDates.push(date);
        }
each results in the same JavaScript runtime error: I'm missing a ).
I'm also using a similar method for floats that works just fine:
        @foreach (var v in Model.Items)
        {
            @:values.push(parseFloat(@v.Value));
        }
An example of the rendered JavaScript is:
            startDates.push(new Date(1/1/2016 12:00:00 AM));
            startDates.push(new Date(2/1/2016 12:00:00 AM));
            startDates.push(new Date(3/1/2016 12:00:00 AM));
            startDates.push(new Date(4/1/2016 12:00:00 AM));
            startDates.push(new Date(5/1/2016 12:00:00 AM));
            startDates.push(new Date(6/1/2016 12:00:00 AM));