从母版页调用部分视图时出现 ASP.NET MVC 堆栈溢出异常
当我尝试从主控调用部分视图时,出现堆栈溢出错误。
部分视图:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<form action="/members/TestLoginProcess/" method="post">
U: <input type="text" name="mUsername" /><br />
P: <input type="password" name="mHash" /><br />
<button type="submit">Log In</button>
</form>
“成员”控制器中的操作
[ChildActionOnly]
public ActionResult TestLogin()
{
return PartialView();
}
然后我从母版页调用部分视图:
<!--Excerpt from wopr.master-->
<%= Html.Action("TestLogin", "Members")%>
当我进入调试模式时母版页返回此错误:
{无法计算表达式,因为当前线程处于堆栈溢出状态。}
我不明白如何触发此错误。任何帮助将不胜感激!
I'm getting a stack overflow error when I try to call a partial view from the master.
The Partial View:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<form action="/members/TestLoginProcess/" method="post">
U: <input type="text" name="mUsername" /><br />
P: <input type="password" name="mHash" /><br />
<button type="submit">Log In</button>
</form>
The Action in the "Members" controller
[ChildActionOnly]
public ActionResult TestLogin()
{
return PartialView();
}
Then I call the partial view from the master page:
<!--Excerpt from wopr.master-->
<%= Html.Action("TestLogin", "Members")%>
When I go into debug mode the master page returns this error:
{Cannot evaluate expression because the current thread is in a stack overflow state.}
I don't understand how this error is getting triggered. any help would be much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我以前见过这个错误。就我而言,当我在操作方法中为 Html.RenderAction 或 Html.Action 返回对 View() 而不是 PartialView() 的调用时,就会发生这种情况。
希望这对某人有帮助。
I have seen this error before. In my case it happened when i returned a call to View() rather than PartialView() for Html.RenderAction or Html.Action in my action methods.
Hope this helps someone.
更改
将
<%= Html.Action("TestLogin", "Members")%>
为
<%= Html.RenderPartial("TestLogin", "Members" 时会发生什么);%>
?另请注意,有一个 ;在命令的末尾。错过这个,你会得到另一个错误。
What happens when you change
<%= Html.Action("TestLogin", "Members")%>
to
<%= Html.RenderPartial("TestLogin", "Members");%>
?Please also note there is a ; at the end of the command. Miss this and you'll get another error.
我得到了完全相同的结果,因为我正在加载一个用户控件,该控件本质上是一个菜单栏,但充满了 Html.Action(),而不是 Html.ActionLink(),因此它不断调用 Action,并且因为它返回到继承相同母版页的页面正在一次又一次地调用它。
所以是的,我的问题是我使用了错误的关键字。
I got the exact same thing because I was loading a user control that was essentially a menu bar, but full of Html.Action(), rather than Html.ActionLink(), so it was continuously calling the Action and because it went back to a page that inherited the same masterpage, was calling it again...and again...and again.
So yeah my problem was I was using the wrong keyword.