gpt4 book ai didi

jquery - "A circular reference was detected while serializing an object of type ' 系统.Reflection.RuntimeModule '"

转载 作者:行者123 更新时间:2023-11-30 23:51:48 41 4
gpt4 key购买 nike

我正在尝试使用 jQuery 以 JSON 结果返回 MVC 模型的对象。我收到一条失败消息:

A circular reference was detected while serializing an object of type 'System.Reflection.RuntimeModule'

这是我的 Controller ,我将在其中返回 Json 结果

public ActionResult populateData(string application, string columns, string machine, string pages, string startDate, string endDate)
{

ErrorPage _objError = new ErrorPage();
_objError.ErrorData = dbl.GetDataTable(DbConnectionString, Table, whereCondition, columns);


//Column description: Name and Type
var columnlist = new Dictionary<string, System.Type>();
foreach (System.Data.DataColumn column in _objError.ErrorData.Columns)
{
var t = System.Type.GetType( column.DataType.FullName );
columnlist.Add(column.ColumnName, t);
}

_objError.ErrorColumns = columnlist;


//DataSourceRequest result = _objError.ToDataSourceResult(request);

if (_objError.ErrorData.Rows.Count > 0)
Message = "Showing Error log for " + AppName + " . To Change the application or filtering options please select the appropriate application from Application Dropdown";
else
Message = "No errors found for " + AppName + " in last 24 hours.";


return Json(_objError);
}

这里我对 Controller 方法进行 Ajax 调用:

$.ajax({
type: "POST",
url: '@Url.Content("~/Common/PopulateData")',
contentType: "application/json; charset=utf-8",
dataType: 'json',
data: JSON.stringify({ application: app, columns: columns, machine: machine, pages: pages, startDate: startDate, endDate: endDate }),
success: function (data) {
alert("Success");
},
error: function (error) {
alert('error; ' + eval(error));
alert('error; ' + error.responseText);
}
});

请帮助如何将 Model 类对象返回到 Ajax 调用后?

最佳答案

我们来寻求解决方案

我用下面的代码集修改了我的代码,它对我有用

public JsonResult populateData(string application, string columns, string machine, string pages, string startDate, string endDate)
{
ErrorPage _objError = new ErrorPage();
var ErrorResult = _objError.GetErrorData(application, columns, machine, pages, startDate, endDate);


var result = JsonConvert.SerializeObject(ErrorResult.ErrorData, Formatting.Indented,
new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});

return Json(result, JsonRequestBehavior.AllowGet);
}

我们需要序列化对象,而不是直接发送 Model 对象。

谢谢。

关于jquery - "A circular reference was detected while serializing an object of type ' 系统.Reflection.RuntimeModule '",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31008219/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com