views:

192

answers:

3

Hey there everyone,

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  A: 

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.

griegs
I'll try it when i get to work tomorrow
quakkels
Good luck @quakkels
griegs
Thanks for the help and the wishes. Unfortunately, when I tried RenderPartial I got this error: Cannot implicitly convert type 'void' to 'object'
quakkels
I took the "=" out and that took care of that error. New errors now :-( I'm gonna troubleshoot this for a while before updating this post.
quakkels
A: 

OK... I have it working now. The weird thing is that the code that I have now is exactly the same as the code I posted in my question with the exception of the names of the controller and action.

I copied a working partial view and call to my "Members" controller. then I methodically changed one thing about it at a time until I had replicated the code in my question above. Now it works fine. I am completely befuddled and my confidence in MVC is shaken to the foundation.

quakkels
A: 

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.

George R