0
votes

I have a DateTime that is rendering in the grid via ClientTemplate() like this:

/Date(1294030800000)/

I know it is a valid date.

Has anyone seen this or can provide a clue as to what I am doing wrong?

1
That's how .Net serializes dates to JSON. - SLaks
That's helpful thanks for that Slaks. - Mike Cheel

1 Answers

2
votes

Here is what I did (thanks to SLaks for pointing out that it was a JSON date) which reminded me that the Telerik grid serializes responses as JSON when in Ajax mode.

I created a helper function in my view:

<script type="text/javascript" language="javascript">
    function ConvertToDateFromJSON(jsonDate) {
        var regex = /-?\d+/;
        var numbers = regex.exec(jsonDate);
        var d = new Date(parseInt(numbers[0]));
        return d;
    }
</script>   

And then the call to ClientTemplate goes like this:

columns.Bound(model => model.DateAdmitted)              
    .Template(o => o.DateAdmitted.ToString("d"))
    .ClientTemplate(
         "<#= $.telerik.formatString('{0:MM/dd/yyyy}', ConvertToDateFromJSON(DateAdmitted)) #>"
    );