Note that there are some explanatory texts on larger screens.

plurals
  1. PORefreshing ViewModel after deleting data in Knockout.js
    primarykey
    data
    text
    <p>I am using Knockout for binding data of a form to the table,now what i ma facing is that when i am deleting the data from the table it goes to server side and delete the data as well but that data remains there unless we refresh the page which not pratical.So what i tried that i am calling the index method on server side which gives me the list of the datas after refreshing the database but when i am doing this.that refreshed datas are appended to the data that remain on the view.i mean it shows the remaing datas and refreshed data both but pratically it shows only the refreshed datas. My code:</p> <pre><code>&lt;table id="table2" style="border: double"&gt; &lt;thead&gt; &lt;tr&gt; &lt;td&gt;Ticket ID&lt;/td&gt; &lt;td&gt;Ticket Type&lt;/td&gt; &lt;td&gt;No of Tickets&lt;/td&gt; &lt;td&gt;Ticket Price&lt;/td&gt; &lt;td&gt;Start Date&lt;/td&gt; &lt;td&gt;End Date&lt;/td&gt; &lt;td&gt;Action&lt;/td&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;!--Iterate through an observableArray using foreach--&gt; &lt;tbody id="ticketid" data-bind="foreach:TicketDatas"&gt; &lt;tr style="border: solid" data-bind="click: $root.getselectedTicket" id="updtr"&gt; &lt;td data-bind="text:TicketId"&gt;@*&lt;span data-bind="text:No_Of_Ticket"&gt;&lt;/span&gt;*@&lt;/td&gt; &lt;td data-bind="text:SelectedTicketType"&gt;@*&lt;span data-bind="text:No_Of_Ticket"&gt;&lt;/span&gt;*@&lt;/td&gt; &lt;td data-bind="text:No_Of_Ticket"&gt;@*&lt;span data-bind="text:No_Of_Ticket"&gt;&lt;/span&gt;*@&lt;/td&gt; &lt;td data-bind="text:Ticket_Price"&gt;@*&lt;span data-bind="text:Ticket_Price"&gt;&lt;/span&gt;*@&lt;/td&gt; &lt;td data-bind="text:Start_Date"&gt;@*&lt;span data-bind="text:Start_Date"&gt;&lt;/span&gt;*@&lt;/td&gt; &lt;td data-bind="text:End_Date"&gt;@*&lt;span data-bind="text:End_Date"&gt;&lt;/span&gt;*@&lt;/td&gt; &lt;td&gt;&lt;button id="deletelink"&gt;Delete&lt;/button&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;script type="text/javascript"&gt; $("#deletelink").live('click', function () { if (confirm('Are you sure to Delete this ticket ??')) { var deleteLink = $(this); var tableRow = deleteLink.closest('tr'); var firstCell = tableRow.find('td:first-child'); var tickid = firstCell.text(); //var tickid = $("#table2 tbody tr td:eq(0)").html(); $.ajax({ type: "POST", data: { id: tickid }, url: "Ticket/DeleteTicket", //data: "{id:" + ko.toJSON(id) + "}", success: function (data) { self.TicketDatas.remove(data); alert("Record Deleted Successfully"); //ko.mapping.fromJS(self.TicketDatas, data) //GetTickets();//Refresh the Table }, error: function (error) { alert(error.status + "&lt;--and--&gt; " + error.statusText); } }); // alert("Clicked" + employee.EmpNo) } }); function GetTickets() { //Ajax Call Get All Employee Records $.ajax({ type: "GET", cache: false, url: "Ticket/GetAllTickets", contentType: "application/json; charset=utf-8", data: {}, dataType: "json", success: function (data) { for (var i = 0; i &lt; data.length; i++) { self.TicketDatas.push(data[i]); } }, error: function (error) { alert(error.status + "&lt;--and--&gt; " + error.statusText); } }); //Ends Here } &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload