Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How can i update the self.contacts = ko.observableArray([]) to include the updated the UI
JavaScript
self.updateContactFromForm = function (formElement) {
    var contractId = $("#editContact input[name$='ContactId']").val();
    var contact = $(formElement).serialize();

    if ($(formElement).valid()) {
        $.ajax({ //ajax call here})
            .done(function (contact) {

                alert("Contact Updated");

            });
    }
}
Posted
Comments
Sunasara Imdadhusen 22-May-14 8:47am    
@Adam, using this code are you getting any error?
Adam Jones 22-May-14 10:00am    
No errors and the UI updates on a refresh

1 solution

You are adding the contact to the server with the ajax call I presume?
Thats why its there after a page resfresh.

In the succeshandler of the ajax call you'll need to push it into the observable array.

self.contacts.push(contact);

Now it should show up directly.
 
Share this answer
 
Comments
Adam Jones 30-May-14 6:22am    
I have tried this but this add the contact to the array instead of replacing it.
i can fudge it be forcing a refresh on success

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