Ashok Bhattarai Ashok Bhattarai - 4 months ago 5x
Javascript Question

Date Binding in Asp.Net with KnockoutJS

I am having trouble in binding datetime in beatpicker while fetching data from the database. In the picker it renders as: "/Date(1465323300000)/" In the following code I have exclude the Stored Procedures, Handler and Utility Connections. I've tried a lot using moment.js but it doesnot work. It is a N-Tier Architecture, the different parts as follows:


public class ATTRenounced
public string compcode { get; set; }
public int regno { get; set; }
public string boid_from { get; set; }
public string boid_to { get; set; }
public int SHolderNoFrom { get; set; }
public int SHolderNoTo { get; set; }
public int rkitta { get; set; }
public string username { get; set; }
public DateTime entrydate { get; set; }
public string Action { get; set; }
public string Fname { get; set; }
public string BOID { get; set; }
public string Name { get; set; }



public JsonResponse GetDematRenouncedEntry(string compcode, int regno)
JsonResponse response = new JsonResponse();

DLLRenounced objDll = new DLLRenounced();
response.ResponseData = objDll.GetDematRenouncedEntry(compcode, regno);

response.IsSucess = true;

catch (Exception ex)
response.Message = ex.Message;
response.IsSucess = false;

return response;



public List<ATTRenounced> GetDematRenouncedEntry(string compcode, int regno)
string spName = "";
DataSet ds2 = new DataSet();
List<ATTRenounced> lstRenouncedDematEntry = new List<ATTRenounced>();
SqlParameter[] param2 = new SqlParameter[2];
param2[0] = new SqlParameter("@CompCode", compcode != null ? compcode : null);
param2[1] = new SqlParameter("@regno", regno != null ? regno : 0);
spName = "GetDematRenouncedEntry";
ds2 = DAO.gettable(spName, param2);

if (ds2.Tables[0].Rows.Count > 0)
foreach (DataRow dr2 in ds2.Tables[0].Rows)
ATTRenounced objATT2 = new ATTRenounced();
objATT2.compcode = dr2["compcode"].ToString();
objATT2.regno = int.Parse(dr2["regno"].ToString());
objATT2.boid_from = dr2["boid_from"].ToString();
objATT2.boid_to = dr2["boid_to"].ToString();
objATT2.entrydate = Convert.ToDateTime(dr2["entrydate"].ToString());
objATT2.rkitta = int.Parse(dr2["rkitta"].ToString());

return lstRenouncedDematEntry;

and KO as:


if (obj.ResponseData != null) {
if (obj.ResponseData.length > 0) {
var DematRenouncedEntry = obj.ResponseData[0];


and View as:


<input type="text" id="txtEntryDate" data-beatpicker="true" class="form-control"
data-bind="value:entrydate" maxlength="10" onblur="return valFutureDate(this,'Y',true);"
onpaste="return false" onkeypress="return isNumberKey(event)"
placeholder="YYYY.MM.DD" />


The data returned from the server is apparently serialized using Microsoft JsonSerializer that uses a non-standard format when serializing DateTime properties. See this answer for more details:

What you need to do before you can do anything with the date on the client is to parse it as Date. In your case you could modify DematRenounced.js as follows:

self.entrydate(new Date(parseInt(DematRenouncedEntry.entrydate.replace("/Date(", "").replace(")/",""), 10)));