[英]Partial View: An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll
I know there are numerous posts already about this but i couldn't seem to fix the error. 我知道已经有很多关于此的帖子,但是我似乎无法修复该错误。
I am getting the above error (Title) in my Partial View which i believe means i have an infinite loop but i am not sure why this is happening. 我在我的局部视图中遇到上述错误(标题),我认为这意味着我有一个无限循环,但我不确定为什么会这样。 Please see below:
请看下面:
HomeController HomeController的
public ActionResult UserTable()
{
manager = new Manager();
var data = manager.GetAllUsers();
var userDetails = from u in data
select new UserDetail
{
UserID = u.Id,
Username = u.Name,
UserLogin = u.Login,
FirstName = u.FirstName,
Surname = u.Surname,
Email = u.Email,
Active = Convert.ToInt32(u.Active),
RightID = u.RightsId,
GroupID = u.GroupsId,
};
return View(userDetails.ToList());
}
UserTable (PartialView) UserTable(PartialView)
@model IEnumerable<WebApplication1.Models.UserDetail>
@Html.Action("UserTable")
<br />
<div>
<table class="table">
<thead>
<tr>
//Table Headers
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
//Various @Html.DisplayFor()
</tr>
}
</tbody>
</table>
</div>
Index (View) 索引(查看)
@{Html.RenderPartial("UserTable");}
If you want me to clarify anything or you want any further details please do not hesitate to ask. 如果您想让我澄清任何事情,或者想要进一步的细节,请随时提出。 Thank you in advance.
先感谢您。
PS The error is occuring in the UserTable Method. PS该错误发生在UserTable方法中。
So I found a solution to my problem with the help of the hints from Stephen and Alexander in the comments. 因此,借助Stephen和Alexander在评论中的提示,我找到了解决问题的方法。 For me if I used Render Partial it didn't execute the Method for each partial view therefore returning null which is why i tried the Html.Action, but this causes an infinite loop, however if I use Render Action then the solution will execute the Methods, Hope this helps anyone that has the same problem.
对我来说,如果我使用Render Partial,则它不会为每个局部视图执行Method,因此返回null,这就是为什么我尝试了Html.Action的原因,但这会导致无限循环,但是如果我使用Render Action,则解决方案将执行方法,希望这对有相同问题的任何人有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.