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
put
@{
Layout = string.Empty;
}
in top of your partial View .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With