0

我最近對我的數據庫做了一個修改 - 我給某些表添加了外鍵關係,並且這樣做了某些AJAX/Json調用似乎不再接受我試圖發送它的數據。從控制器通過Ajax/Json傳遞一個外鍵關係的模型

我有一個模式叫汽車(我可以通過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; } 
} 

現在有一個額外的元素:

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; } 
} 

所以Ajax調用是這樣的:

function GetCars() {  
     $.ajax({ 
      cache: false, 
      url: '@Url.Action("GetCarList", "Line")', 
      type: 'POST', 
      success: function (data) { 
       alert('it worked!'); 
      } 
     }); 
    } 

我也使用unitofwork /存儲庫模式順便說一句,這是控制器(它曾經工作得很好):

[HttpPost] 
public JsonResult GetCarList() 
{ 
    var carlist = unitOfWork.CarRepository.Get().ToList(); 
    return Json(carlist); 
} 

不管我現在做的,我不能得到的數據返回給Ajax調用(警報不火)。如果我將CarRepository替換爲沒有任何外鍵關係的另一個模型存儲庫,它將再次運行。

在此先感謝

+0

您是否在WorkCenter實體中添加了CarsId? – 2014-10-28 22:19:33

回答

相關問題