Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC3 Razor syntax help - I'm getting stuck in an infinite loop

I'm trying to convert a small mvc2 application to the mvc3 razor syntax. In my mvc2 application I'm using the aspx view engine with a master page. Following the example from Steven Sanderson's Pro MVC2 book 2nd edition, in the masterpage I call a controller action that renders a partial view for each entity. This is working correctly.

 <div id="categories">
    <% Html.RenderAction("Menu", "Nav"); %>
</div>

using _layout.cshtml and razor I'm trying this. Here is where my problem comes in.

 <div id="categories">
    @{ 
        Html.RenderAction("Menu", "Nav"); 

    }
</div>

This is causing an infinite loop now and I'm getting oddly enough a StackOverflowException. Can anyone help me correct the problem? Here is the controller method code.

  public ViewResult Menu(string personId)
    {
        Func<string, NavLink> makeLink = pId => new NavLink
        {
            Text = pId ?? "Home"
            , RouteValues = new RouteValueDictionary(new { controller = "Person", action = "Person"})

        };

        List<NavLink> navLinks = new List<NavLink> {makeLink(null)};


        Func<Person, NavLink> makeLink2 = p => new NavLink
        {
            Text = p.Name ?? "Home"
            , RouteValues = new RouteValueDictionary(new { controller = "Person", action = "Person", personId = p.Id })

        };

        var people = usersRepository.People.OrderBy(x => x.Name);
        var peopleLinks = EnumerableHelpers.MakeLinks(people, makeLink2);

        navLinks.AddRange(peopleLinks);

        return View("_menu", navLinks);
    }

Any help or tips is most appreciated.

Thanks,
~ck in San Diego

like image 309
Hcabnettek Avatar asked Nov 22 '10 16:11

Hcabnettek


1 Answers

put

@{
    Layout = string.Empty;
} 

in top of your partial View .

like image 200
rashid omrani Avatar answered Sep 28 '22 05:09

rashid omrani