我這樣定義無法序列化對象
public class Planilla
{
[Key]
public int IDPlanilla { get; set; }
[Required(ErrorMessage = "*")]
[Display(Name = "Dirección de Negocio")]
public int IDDireccionDeNegocio { get; set; }
[Required (ErrorMessage = "*")]
public string Nombre { get; set; }
[Display(Name = "Descripción")]
public string Descripcion { get; set; }
public bool Activo { get; set; }
[ScriptIgnore]
public virtual DireccionDeNegocio DireccionDeNegocio { get; set; }
}
一個模型,我在我的控制器的方法返回此模式的第一個元素
[HttpPost]
public ActionResult GetElements(string IDCampana)
{
Planilla query = db.Planillas.First();
return Json(query);
}
是我的問題,當我從客戶端調用此方法會拋出一個錯誤,說的是
檢測到循環引用嘗試序列化 System.Data.Entity.DynamicProxies.Planilla_7F7D4D6D9AD7AEDCC59865F32D5D02B4023989FC7178D7698895D2CA59F26FEE
Debugging my code I realized that the object returned by the execution of the method
首先it's a
{System.Data.Entity.DynamicProxies.Planilla_7F7D4D6D9AD7AEDCC59865F32D5D02B4023989FC7178D7698895D2CA59F26FEE}instead a Model of my namespace like
Example.Models.DireccionDeNegocio`。
爲什麼我做錯了?因爲我嘗試過使用其他模型和工作的好
你能提供一個測試片段來突出你的錯誤嗎? –