从母版页调用部分视图时出现 ASP.NET MVC 堆栈溢出异常

发布于 2024-09-01 08:50:32 字数 848 浏览 6 评论 0原文

当我尝试从主控调用部分视图时,出现堆栈溢出错误。

部分视图:

<%@ 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甚是思念 2024-09-08 08:50:32

我以前见过这个错误。就我而言,当我在操作方法中为 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.

唠甜嗑 2024-09-08 08:50:32

更改

<%= 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.

提赋 2024-09-08 08:50:32

我得到了完全相同的结果,因为我正在加载一个用户控件,该控件本质上是一个菜单栏,但充满了 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文