呈现索引视图时出现异常



在索引视图渲染时引发此异常:

"InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first."

这是索引视图:

@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.pageGroup.GroupTitle)
</td>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.ShortDescription)
</td>
<td>
@Html.DisplayFor(modelItem => item.Text)
</td>
<td>
@Html.DisplayFor(modelItem => item.ShowInSlider)
</td>
<td>
@Html.DisplayFor(modelItem => item.ImageName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Visit)
</td>
<td>

@item.CreateData.ToShamsi();
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.PageID }) |
@Html.ActionLink("Details", "Details", new { id=item.PageID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.PageID })
</td>
</tr> }

以及这一行中抛出的exeption:

@Html.DisplayFor(modelItem => item.pageGroup.GroupTitle)

问题出在哪里?

如果你感到困惑,请告诉我放上你想要的部分的代码

这是我的连接字符串:

<connectionStrings>
<add name="MyCmsContext" connectionString="data source=.;    initial catalog=MyCmsDB;persist security info=True;     Integrated Security=True; " providerName="System.Data.SqlClient" MultipleActiveResultSets="true"  />

您需要在连接字符串中允许MARS。将MultipleActiveResultSets=true添加到连接字符串的提供者部分。

"Server=xxxx;Database=xxxxx;xxxxx MultipleActiveResultSets=true"

最新更新