ASP.NET MVC stack overflow exception when calling a partial view from master page

给你一囗甜甜゛ 提交于 2019-12-01 20:26:02

问题


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!


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/2814824/asp-net-mvc-stack-overflow-exception-when-calling-a-partial-view-from-master-pag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!