Click here to Skip to main content
15,667,847 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

I am learning MVC 4 and got struck with problem. I am trying to load all menus in Layout page using partial View.

Here is the content from my Layout Page :
Razor
@{Html.RenderAction("TopMenuToLoad", "TopMenu");}


Content from my Partial View

@model  IEnumerable<OrderProcessing.Database.Menu>

<table>
    
       @foreach (var item in Model)
        {
            <tr>
                <td>
                    Html.ActionLink(item.MenuName, item.ControllerPath)
                </td>
            </tr>
        }
    

</table>


Content from my Controller of Partial View:

C#
namespace OrderProcessing.Controllers
{
    public class TopMenuController : Controller
    {
        //
        // GET: /Menu/
        [ChildActionOnly]
        public ActionResult TopMenuToLoad()
        {
            MVCLearningDBEntities Entities = new MVCLearningDBEntities();
            var Menus = Entities.Menus.Where(x => x.IsActive == true).ToList();
            return View(Menus);
        }

    }
}



When i run this application in debugging mode, It keeps on calling TopMenuToLoad until it throws stack overflow exception.

Thanks,
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900