I recently made a change to my database - I added foreign key relationships to certain tables and in doing so certain AJAX/Json calls no longer seem to accept the data I am trying to send it.
I had a model called Cars (which I could call via Ajax):
public partial class Cars
{
public int Id { get; set; }
public Nullable<int> WorkCenterId { get; set; }
public string Name { get; set; }
public string SerialNumber { get; set; }
}
which now has an additional element:
public partial class Cars
{
public int Id { get; set; }
public Nullable<int> WorkCenterId { get; set; }
public string Name { get; set; }
public string SerialNumber { get; set; }
public virtual WorkCenter WorkCenter { get; set; }
}
so the Ajax call is this:
function GetCars() {
$.ajax({
cache: false,
url: '@Url.Action("GetCarList", "Line")',
type: 'POST',
success: function (data) {
alert('it worked!');
}
});
}
I am also using unitofwork/repository pattern BTW and this is the controller (which used to work fine):
[HttpPost]
public JsonResult GetCarList()
{
var carlist = unitOfWork.CarRepository.Get().ToList();
return Json(carlist);
}
No matter what I do now, I cannot get the data returned to the Ajax call (the alert does not fire). If I replace the CarRepository with another model repository that does not have any foreign key relations it will work again.
Thanks in advance