I am currently attempting to update my table by making an Ajax call using the following code snippet:
var client = {};
client.ClientId = row.find(".ClientId").find("span").html();
client.Name = row.find(".Name").find("span").html();
client.Type = row.find(".Type").find("span").html();
client.Code = row.find(".Code").find("span").html();
client.Accounting = row.find(".Accounting").find("span").html();
$.ajax({
type: "POST",
url: "/Home/UpdateClient",
data: '{client:' + JSON.stringify(client) + '}',
contentType: "application/json; charset=utf-8",
dataType: "json"
});
});
However, upon clicking to update the value, I encounter a System.NullReferenceException. I'm struggling to identify where the issue lies.
Below is my Controller Code:
public ActionResult UpdateClient(Client client)
{
using (ClientsEntities entities = new ClientsEntities())
{
Client updatedClient = (from c in entities.Clients
where c.ClientId == client.ClientId
select c).FirstOrDefault();
updatedClient.Name = client.Name;
updatedClient.Type = client.Type;
updatedClient.Code = client.Code;
updatedClient.Accounting = client.Accounting;
entities.SaveChanges();
}
return new EmptyResult();
}