我创建控制器函数获取数据为json。在视图中我使用此函数来获取ajax请求中的数据。当我在返回栏中给出模型时
return Json(model, JsonRequestBehavior.AllowGet);
像这样我得到了这个错误
,而串行化类型&#39的一个目的是检测到一个循环引用; System.Data.Entity.DynamicProxies.InformationSecurityD_296951563FA1E6AF124B046E5DF9F5DA6F8E47C12B96ADB9C71A501E9BDE702D'
当我在这样的回归块中给json时
return Json(json, JsonRequestBehavior.AllowGet);
然后它给出了双序列化问题,我无法处理它
控制器功能
[HttpPost]
public JsonResult GetallData(int id)
{
MultipleViewModel model = new MultipleViewModel();
List<InformationSecurityData> iso = db.InformationSecurityDatas.Where(x => x.Supplier_ID == id).ToList();
List<SurveyForm> tender = db.SurveyForms.Where(x => x.Supplier_ID == id ).ToList();
List<ProcurementData> procurement = db.ProcurementDatas.Where(x => x.Supplier_ID == id ).ToList();
List<Supplier> supp = db.Suppliers.Where(x => x.Supplier_ID == id).ToList();
model.Inf_Sec_Dat = iso;
model.Proc_Dat = procurement;
model.Tender_Dat = tender;
model.Supp_dat = supp;
var serializerSettings = new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects };
string json = JsonConvert.SerializeObject(model, Formatting.Indented, serializerSettings);
MultipleViewModel model2 = JsonConvert.DeserializeObject<MultipleViewModel>(json);
return Json(model, JsonRequestBehavior.AllowGet);
}
视图
$(document).ready(function () {
$("#GetallData").click(function () {
var id = $("#id").val();
$.ajax({
url: '/Dashboard/GetallData/'+id,
type: 'POST',
cache: false,
dataType: 'json',
contentType: 'application/json',
success: function (data) {
alert("success ");
//var myJSON = JSON.stringify(obj);
Objdata = jQuery.parseJSON(data);
alert(Objdata);
if (Objdata.Inf_Sec_Dat) {
$.each(Objdata.Inf_Sec_Dat, function (i, item) {
iso_data.push(item.Total_Score);
});
alert(iso_data);
}
bindChart(iso_data);
if (Objdata.Tender_Dat) {
$.each(Objdata.Tender_Dat, function (i, item) {
tender_data.push(item.Total_Score);
});
}
bindChart2(tender_data);
//bindChart3(tender_data);
},
error: function (response) {
alert("error_tender" + response);
}
});
});
});
请帮助我无法处理