When I parse a DateTime to json in .Net it returns a string (i.e. "/Date(1249335194272)/"
). How do I make it return a js Date object constructor not wrap in a string?
// js server code
var dteNow = <%= jsonDateNow %>;
// js rendered code
var dteNow = "/Date(1249335477787)/";
// C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.Script.Serialization;
using System.Web.UI.WebControls;
namespace testing{
public partial class iTaxPrep : System.Web.UI.Page
{
protected string jsonDateNow;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
jsonDateNow = new JavaScriptSerializer().Serialize(DateTime.Now);
}
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…