In the _Layout.cshtml file , I have the following entry:
@Html.Action("LoadPagesStructure", "Page")
Inside the PageController class , LoadPagesStructure looks like this:
[ChildActionOnly]
public ActionResult LoadPagesStructure()
{
ViewModel.Pages = new List<string>() {"page1", "page2", "page3"};
return View();
}
Finally, my view of LoadPagesStructure.cshtml is as follows:
@inherits System.Web.Mvc.WebViewPage<dynamic>
<ul>
@foreach (var page in View.Pages) {
<li>
@Html.ActionLink(page, "Index", "Home")
</li>
}
</ul>
Unfortunately, an exception is thrown after execution:
System.InvalidOperationException: Child actions are not allowed to perform redirect actions.
How can I dynamically create links to my pages?
PS: I know I can do it like this: <a href="@page">@page</a>. However, I think this is the wrong way, because routing control is not possible here.
Hi