Click here to Skip to main content
15,843,327 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am retrieving data from database in MVC core using jquery Ajax. All the fields have successfully retrieved and work well but the data fields cannot be retrieved. For date i used the date control i.e. . Please check only the following fields:

$("#dtpEmpBirthDate").val(response[i].EmpBirthDate);

$("#dtpEmpJoiningDate").val(response[i].EmpJoiningDate);


All the data is ok but the date fields cannot be updated from the response.

What I have tried:

JavaScript
<pre>//Retrieve the Employee record using the selected Employee ID
        $.ajax({
            url: "/RetrieveData/RetrieveEmployeeRecordByID",
            type: "GET",
            dataType: "json",
            data: { "id": empID },
            success: function (response) {
                for (var i = 0; i < response.length; i++) {
                    $("#txtEmployeeCode").val(response[i].EmpCode);
                    $("#txtEmpFirstName").val(response[i].EmpFirstName);
                    $("#txtEmpLastName").val(response[i].EmpLastName);
                    $("#txtEmpFullName").val(response[i].EmpFullName);
                    $("#dtpEmpBirthDate").val(response[i].EmpBirthDate);
                    $("#cmbEmpGender").val(response[i].EmpGender);
                    $("#txtEmpFullAddress").val(response[i].EmpFullAddress);
                    $("#dtpEmpJoiningDate").val(response[i].EmpJoiningDate);
                    $("#cmbEmpReligion").val(response[i].EmpReligion);
                    $("#txtEmpTelephoneNumber").val(response[i].EmpTelephoneNumber);
                    $("#txtEmpMobileNumber").val(response[i].EmpMobileNumber);
                    $("#txtEmpEmailAddress").val(response[i].EmpEmailAddress);
                    $("#cmbEmpBranchCode").val(response[i].EmpBranchCode);
                    $("#cmbEmpDepttCode").val(response[i].EmpDepttCode);
                    $("#cmbEmpOccupationCode").val(response[i].EmpOccupationCode);
                    $("#cmbEmpNationality").val(response[i].EmpNationality);
                    $("#cmbEmpMaritalStatus").val(response[i].EmpMaritalStatus);
                    $("#txtEmpDependent").val(response[i].EmpDependent);
                    $("#txtEmpEmergencyContact").val(response[i].EmpEmergencyContact);
                    $("#txtEmpEmergencyContactPerson").val(response[i].EmpEmergencyContactPerson);
                    $("#txtEmpEmergencyContactPersonRelation").val(response[i].EmpEmergencyContactPersonRelation);
                    $("#txtEmployeePictureFullPath").val(response[i].EmpPicture);                  
                    } //End of for Loop
            },
            error: function (response) {
                alert("Record cannot be displayed", response.responseText);
            }
        });
Posted
Updated 25-Feb-19 0:47am

1 solution

You need to cast the date object to string in "/RetrieveData/RetrieveEmployeeRecordByID".
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900