title: 500 error with knockout delete
body: <p>I am getting a 500 error when I try and delete an item in my list using ajax.</p>
  
  <p>From using the console on Chrome combined with Fiddler, a null reference on the Id is the  issue. Debugging through Chrome's console shows that the announcement object does have an Id.</p>
  
  <p>I was under the impression 500 errors came from the server, but I have a break point on the function path it's calling and not getting hit.</p>
  
  <p>Is there anything that is staring me in the face as to why this would be setting the announcement.Id to null?</p>
  
  <p><strong>controller:</strong></p>
  
  <pre><code>public JsonResult DeleteAnnouncement(int Id)
          {
              if(repository.DeleteAnnouncement(Id))
              {
                  return Json(repository.GetAllAnnouncements(), JsonRequestBehavior.AllowGet);
              }
              return Json(null);
          }
  </code></pre>
  
  <p><strong>repository:</strong></p>
  
  <pre><code>public bool DeleteAnnouncement(int Id)
          {
              var model = (from a in db.DbAnnouncement
                                       where a.Id == Id
                                       select a).SingleOrDefault();
              if (model.Id != 0)
              {
                  db.DbAnnouncement.Remove(model);
                  db.SaveChanges();
                  return true;
              }
              else
              {
                  return false;
              }
          }
  </code></pre>
  
  <p><strong>js script:</strong></p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          function AnnouncementViewModel() {
              //Make the self as 'this' reference
              var self = this;
              //Declare observable which will be bind with UI
              self.Id = ko.observable("");
              self.Title = ko.observable("");
              self.Details = ko.observable("");
              self.DTCreated = ko.observable("");
              self.LastUpdated = ko.observable("");
              self.CreatedUser = ko.observable("");
              self.UpdatedUser = ko.observable("");
              self.VersionNum = ko.observable("");
              self.StartDT = ko.observable("");
              self.ExpiryDT = ko.observable("");
              self.Enabled = ko.observable("");
              self.GroupID = ko.observable("");
              self.URLLink = ko.observable("");
  
              var Announcement = {
                  Id: self.Id,
                  Title: self.Title,
                  Details: self.Details,
                  DTCreated: self.DTCreated,
                  LastUpdated: self.LastUpdated,
                  CreatedUser: self.CreatedUser,
                  UpdatedUser: self.UpdatedUser,
                  VersionNum: self.VersionNum,
                  StartDT: self.StartDT,
                  ExpiryDT: self.ExpiryDT,
                  Enabled: self.Enabled,
                  GroupID: self.GroupID,
                  URLLink: self.URLLink
              };
  
              self.Announcement = ko.observable();
              self.Announcements = ko.observableArray(); // list of announcements
  
              // Delete announcement
              self.delete = function (Announcement) {
                  if (confirm('Are you sure to Delete "' + Announcement.Title + '"?')) {
                      $.ajax({
                          url: '@Url.Action("DeleteAnnouncement","Announcement")',
                          cache: false,
                          type: 'POST',
                          contentType: 'application/json; charset=utf-8',
                          //data: ko.toJSON(Announcement.Id),
                          data: {Id: Announcement.Id},
                          success: function (data) {
                              self.Announcements.remove(Announcement);
                              alert("Record Deleted Successfully");
                          }
                      }).fail(
                      function (xhr, textStatus, err) {
                          alert(err);
                      });
                  }
              }
  
  
          }
          $(document).ready(function () {
              var viewModel = new AnnouncementViewModel();
              ko.applyBindings(viewModel);
          });
  </code></pre>