0

I am trying to create a dynamic menu layout in ASP.NET MVC 4. What I did is in my shared view I have the following call

@{ Html.RenderAction("Index", "FooterMenu"); }

I have a controller, and a view for my FooterMenu. It also have a model. Now i try to call it however I keep getting this error

System.StackOverflowException was unhandled

Its keep pointing to my index

public ActionResult Index()
{
  return View(db.FooterMenus.ToList());
}

It also say make sure i am not in an infinite loop, or recursion. But my code is fairly simple

2 Answers 2

2

I would suspect that you want to return a PartialView - so that the menu doesn't also render the layout, which renders the menu, which renders the layout, which renders the menu...etc

public ActionResult Index()
{
  return PartialView(db.FooterMenus.ToList());
}
Sign up to request clarification or add additional context in comments.

Comments

1

I believe you are caught in a recursive loop. My guess is that the Index view in FooterMenu is using the shared view, which itself is calling @{ Html.RenderAction("Index", "FooterMenu"); }

2 Comments

Oh, wow okay that make sense, how can i have a partial in shared folder, with data from the table? then
Return a PartialView instead of a View. The View creates a loop as spotted by Queti Mporta but the PartialView will only returns your menu (without layout which calls the menu another time)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.