我正在MVC 5中进行开发,并且在GET上收到一个可以返回多个记录(900+)的错误。
这个页面还发布了一个多行更新,但是我正在接收GET上的无限循环。如果页面返回了大量记录(120ish+),我将得到无限循环错误。这种情况似乎不会发生在记录较少(<100)的页面上,但即使如此,加载页面的时间也比我预期的要长。
以下是错误:
我的代码是否有问题,还是返回到页面的记录数量有问题?有时一页上有900条记录。我可以添加分页,但是将所有记录放在一个页面上对用户来说更有效。用户批量设置页面上的字段值,然后为不同数量的记录更改大容量集值。
我已经尝试过for和foreach循环,但是使用这两种方法都有相同的错误(我不确定在这种情况下最好使用什么)。
我在这方面已经做了一段时间了,我没有发现问题所在。
控制器
public ActionResult PCPList(string location, string pcp)
{
List<PCPListVM> data = new List<PCPListVM>();
//query
data = (from n in db.DataDump
join t in db.TData on n.SubscriberID equals t.SubscriberID into joinedTable
from td in joinedTable.Take(1).DefaultIfEmpty()
where n.PCP == pcp
orderby n.MemberName
select new PCPListVM()
{
ID = n.ID,
MemberName = n.MemberName,
DateOfBirth = n.DateOfBirth,
PCP = n.PCP,
Location = td.Location,
LocationList = db.LocationList.Select(c => new SelectListItem
{
Value = c.LocationID,
Text = c.LocationList,
Selected = c.LocationList.Equals(location)
}).OrderBy(x => x.Text);
}).ToList();
return View(data);
}视图
@model List<Project.ViewModels.PCPListVM>
// loop through records
@if (Model != null && Model.Count > 0)
{
int j = 0;
foreach (var i in Model)
{
<tr>
<td>@j</td>
<td>@i.SubscriberID</td>
<td>@i.MemberName</td>
<td>@i.DateOfBirth</td>
<td>@i.PCP</td>
<td>
@Html.DropDownListFor(a => a[j].Location, (IEnumerable<SelectListItem>)ViewBag.location, "", new { @class = "input-sm" })
</td>
</tr>
j++;
}
}模型
public class PCPListVM
{
[Key]
[Required]
public string SubscriberID { get; set; }
public string MemberName { get; set; }
public DateTime? DateOfBirth { get; set; }
public string PCP { get; set; }
public string Location { get; set; }
public IEnumerable<SelectListItem> LocationList { get; set; }
}更新-
我的测试用例返回1200行。我还试着删除所有的下拉,看看它们是否是问题,网页仍然崩溃。我已经签入控制器,并将正确的记录数量返回到视图模型。
运行分析器后,我看到以下消息: System.Reflection..Get.(.*) = 9.01;您可能过度使用反射。这是个昂贵的手术。
有什么更好的方法可以让我提取这些数据并循环通过它吗?
我在调用堆栈中看到的错误是: System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetId(System.RuntimeTypeHandle)
发布于 2015-12-06 21:31:57
在执行LocationList创建时,请执行以下操作:
LocationList = db.LocationList.Select(c => new SelectListItem
{
Value = c.LocationID,
Text = c.LocationList,
Selected = c.LocationList.Equals(location)
}).OrderBy(x => x.Text).ToList()我认为Json.NET在序列化IEnumerable响应时遇到了一些循环引用问题。
发布于 2015-12-14 23:04:50
在这种情况下,返回的记录数量似乎造成了性能问题。最后,我将记录返回到WebGrid并分页到200,并且不再接收错误消息。
https://stackoverflow.com/questions/34121343
复制相似问题